ipad:弹出窗口未出现在适当的位置

发布于 2024-10-21 09:44:32 字数 1211 浏览 7 评论 0原文

我遇到了这种情况,请帮我解决这个问题,

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];



}   

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

I have a situation here please help me out in this,

1) I have a Table with custom cells
2) Each cell has 2 search bars and 2 lables.

what I was attempting is suppose a user beginEditing a searchBar a popover should appear pointing that search bar.

I have implemented this but popover is not appearing over the desired searchBar moreover height of popover is also too long sometime

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];



}   

Please help me to solve this one.
Thanx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

围归者 2024-10-28 09:44:32

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

您可以使用 searchBar 本身作为“inView”,对于“rect”,使用 searchBar 的边界,而不是使用 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);

The searchBar is inside a cell which is in a table view (which may be in some other view depending on your layout). The problem most likely is that self.view is not the direct parent of searchBar where you are calling this. So using the frame of the searchBar in self.view will give unexpected results.

Instead of using self.view and trying to figure out where the searchBar is relative to that, you can use the searchBar itself for the "inView" and for the "rect", use the searchBar's bounds:

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

Next, to fix the height of the popover, try setting the popover's popoverContentSize instead of the view controller's contentSizeForViewInPopover:

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

Finally, a separate issue but, the minimum height for a datepicker should be 216, not 200:

CGRect pickerFrame = CGRectMake(0,0,300,216);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文