开发者

ipad: popover is not appearing at appropriate place

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:) fo开发者_StackOverflow中文版rControlEvents: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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜