将UITableViewController放在UIPopoverController中

时间:2014-04-21 14:55:29

标签: ios uitableview uipopovercontroller

我正在尝试使用以下代码从UITableViewController(EnrollmentPopoverTableViewController)创建一个弹出框。

然而,我得到一个空白的弹出窗口。

UIViewController *popovercontent = [[UIViewController alloc]init];
UIView * popoverview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 768)];
EnrollmentPopoverTableViewController *EnrollmentPopoverTable=[[EnrollmentPopoverTableViewController alloc] init];
[popoverview addSubview:EnrollmentPopoverTable.tableView];
popovercontent.view=popoverview;
myPopoverController =[[UIPopoverController alloc]initWithContentViewController:popovercontent];
 UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
[self.myPopoverController presentPopoverFromRect:cell.bounds inView:cell.contentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

1 个答案:

答案 0 :(得分:0)

// create the table view controller
EnrollmentPopoverTableViewController *tableViewController =[[EnrollmentPopoverTableViewController alloc] init];

// create a popover using this view controller
myPopoverController =[[UIPopoverController alloc]initWithContentViewController:tableViewController];

// display the view controller from wherever you want to display it
[myPopoverController presentPopoverFromRect:sizeOfPopover inView:view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

你过度复杂了。