【问题标题】:ipad: popover is not appearing at appropriate placeipad:弹出框没有出现在适当的位置
【发布时间】:2011-03-10 21:37:06
【问题描述】:

我这里有个情况,请帮帮我,

1) 我有一个带有自定义单元格的表格 2) 每个单元格有 2 个搜索栏和 2 个标签。

我正在尝试的是假设用户开始编辑搜索栏,弹出框应该指向该搜索栏。

我已经实现了这个,但是弹出框没有出现在所需的搜索栏上,而且弹出框的高度有时也太长了

if (searchBar.tag==10) {
    NSLog(@"Display date popover");
    CGRect pickerFrame = CGRectMake(0,0,300,200);

    UIViewController *tempDateViewController=[[UIViewController alloc] init];

    UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];

    [datePicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];

    [tempDateViewController.view addSubview:datePicker];

    if(!currentPopover)
    {

        currentPopover=[[UIPopoverController alloc] initWithContentViewController:tempDateViewController];
    }
    else {

        [currentPopover setContentViewController:tempDateViewController animated:YES];

    }

    tempDateViewController.contentSizeForViewInPopover=CGSizeMake(320, 300);
    [datePicker release];
    [tempDateViewController release];
    [currentPopover presentPopoverFromRect:searchBar.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];



}   

请帮我解决这个问题。 提前谢谢。

【问题讨论】:

  • 这段代码在什么方法中? searchBar 变量是如何设置的?
  • searchBarDidBeginEditing

标签: objective-c ipad uisplitviewcontroller uipopover


【解决方案1】:

searchBar 位于表格视图中的单元格内(根据您的布局,它可能位于其他视图中)。最有可能的问题是 self.view 不是您调用它的 searchBar 的直接父级。所以在 self.view 中使用 searchBar 的框架会得到意想不到的结果。

您可以将 searchBar 本身用于“inView”和“rect”,而不是使用 self.view 并试图找出 searchBar 的相对位置:

[currentPopover presentPopoverFromRect:searchBar.bounds inView:searchBar 
    permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


接下来,要修复弹出框的高度,请尝试设置弹出框的 popoverContentSize 而不是视图控制器的 contentSizeForViewInPopover:

//tempDateViewController.contentSizeForViewInPopover=CGSizeMake(320, 300);
currentPopover.popoverContentSize = CGSizeMake(320, 300);


最后,一个单独的问题,日期选择器的最小高度应该是 216,而不是 200:

CGRect pickerFrame = CGRectMake(0,0,300,216);

【讨论】:

    猜你喜欢
    • 2012-11-14
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多