push a new tableViewController in a uipopovercontr

2019-05-20 07:52发布

I found this thread, but it still doesn't fix my problem. UIPopoverController automatically resizing to max height on pushViewController

I have a UIPopoverController that pushes a navigationcontroller. When I present this popover, I set the contentSizeForPopover to 340,340. That works fine. In the popover, I have a button, that pushes a new UITableViewController into the already existing UIPopoverController (code below for the tableViewController).

UITableViewController *contentView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
contentView.tableView.delegate = self;
contentView.tableView.dataSource = self;
[self.navigationController pushViewController:contentView animated:YES];
[contentView release];

When the tableView gets pushed, the height grows to the max height of the iPad. When I press the back button, the height still is at the max height and does not go back to the 340,340 height that was defined when the UIPopoverController was originally created. Is there a way to set this value again for the new tableView I created? Thanks.

2条回答
放荡不羁爱自由
2楼-- · 2019-05-20 08:32

All that you have to do is:

-In the viewWillAppear method of the popOvers contentView, add the snippet given below. You will have to specify the popOver's size first time when it is loaded.

-(void)viewWillAppear{
CGSize size = CGSizeMake(width,height);
self.contentSizeForViewInPopover = size;
}
查看更多
smile是对你的礼貌
3楼-- · 2019-05-20 08:48

In my experience with UIPopoverController objects, the popover seems to use the maximum height whenever new content is added to the popover. I send the popover controller a setPopoverContentSize:animated: message every time I change the content, which of course requires me to keep a reference to that popover controller in every object that may cause the popover to resize. You could add that message send right after your sample code in your question to keep the popover from resizing, but it may still resize when you pop off this view from the UINavigationController stack, so another message send may be needed. Maybe each view controller that may appear in the popup will send the setPopoverContentSize:animated: message in its viewWillAppear: method. Each will also have a reference to the popover controller.

查看更多
登录 后发表回答