push a new tableViewController in a uipopovercontroller causes the popover to be resized

那年仲夏 提交于 2019-12-08 00:52:00

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/7957858/push-a-new-tableviewcontroller-in-a-uipopovercontroller-causes-the-popover-to-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!