Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c ipad:popover没有出现在适当的位置_Objective C_Ipad_Uisplitviewcontroller_Uipopover - Fatal编程技术网

Objective c ipad:popover没有出现在适当的位置

Objective c ipad:popover没有出现在适当的位置,objective-c,ipad,uisplitviewcontroller,uipopover,Objective C,Ipad,Uisplitviewcontroller,Uipopover,我这里有个情况请帮我解决一下 1) 我有一张带有自定义单元格的表格 2) 每个单元格有2个搜索栏和2个标签 我尝试的是假设一个用户开始编辑一个搜索栏,一个弹出框应该指向那个搜索栏 我已经实现了这一点,但popover并没有出现在所需的搜索栏上,而且popover的高度有时也太长 if (searchBar.tag==10) { NSLog(@"Display date popover"); CGRect pickerFrame = CGRectMake(0,0,300,200);

我这里有个情况请帮我解决一下

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

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

我已经实现了这一点,但popover并没有出现在所需的搜索栏上,而且popover的高度有时也太长

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



}   
请帮我解决这个问题。
搜索栏位于表格视图(可能位于其他视图中,具体取决于您的布局)中的单元格内。问题很可能是self.view不是您调用它的searchBar的直接父级。因此,在self.view中使用搜索栏的框架将产生意外的结果

不必使用self.view并试图找出搜索栏相对于self.view的位置,您可以将搜索栏本身用于“inView”和“rect”,而使用搜索栏的边界:

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

接下来,要固定popover的高度,请尝试设置popover的PopoOverContentSize,而不是视图控制器的contentSizeForViewInPopover:

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

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

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

这段代码是用什么方法编写的?searchBar变量是如何设置的?searchbardibeginediting