iOS8 popovercontroller高度问题

时间:2014-09-13 11:42:20

标签: objective-c uitableview ios8 uipopovercontroller xcode6

我有一个UIPopovercontroller。 用这种方式呈现它。

BackupPop *backupPop = [[BackupPop alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
backupPop.delegate = self;

backupPop.navigationItem.title = [Language get2:@"Backup"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:backupPop];
assigningBackupRow = button.tag;
backupPopController = [[UIPopoverController alloc] initWithContentViewController:navController];
backupPopController.popoverContentSize = CGSizeMake(200, 150);
CGRect rect = CGRectMake(button.frame.origin.x, button.frame.origin.y + 20 + (button.tag - 30000) * 44, button.frame.size.width, button.frame.size.height);
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

在UIPopovercontroller中,我在viewdidload中有一个UITableView。

funcTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 80) style:UITableViewStylePlain];
[funcTable setDelegate:self];
[funcTable setDataSource:self];
[funcTable setRowHeight:44];
[funcTable setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:funcTable];

iOS8中的问题,虽然我的UITableView的高度为80px,但它只显示为40px。 UITableView的起始位置是正确的,但高度不是。现在,我必须将120px作为高度放到UIPopoverController中的所有UITableView。在iOS7中没有这样的问题。 伙计们,有什么想法吗?感谢。

3 个答案:

答案 0 :(得分:1)

试试这个

iOS 8有一个名为UIPopoverPresentationController的新PopOverController

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@" Main"捆绑:无];     UINavigationController * navController = [storyboard instantiateViewControllerWithIdentifier:@" Terms_NC"];

 navController.preferredContentSize = CGSizeMake(300, 290);

// Present the view controller using the popover style.
navController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navController animated: YES completion: nil];

// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[navController popoverPresentationController];
presentationController.permittedArrowDirections =0;
presentationController.sourceView = self.view;
presentationController.sourceRect = CGRectMake(100, 100, 300, 340);

答案 1 :(得分:0)

我有同样的问题。我所做的是在我呈现我的popover之前,我再次明确地设置了tableview的大小。

[backupPop adjustFrame];
backupPopController.popoverContentSize = backupPop.view.frame.size;
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

您可以在backupPop中添加方法

- (void)adjustFrame {
    CGRect frame = self.view.frame;
    frame.size.height = 80
    frame.size.width = 200;
    self.view.frame = frame;
}

Lemme知道它是否有帮助。

答案 2 :(得分:0)

可能是它的解决方法在稍微延迟后设置内容大小。

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(0.01 * NSEC_PER_SEC)),dispatch_get_main_queue(),^ {             [self.popoverController setPopoverContentSize:CGSizeMake(300,340)animated:YES];            });