Reputation: 5184
I have a design that needs what amounts to a UISplitViewController somewhere other than the root of the app. Since that's illegal for some stupid reason (thanks Apple), I've had to recode certain aspects of it by hand.
The table lays out properly in landscape mode, but when I move it into a popover, I get some odd issues. Originally, I had the popover long enough that it had to shrink to provide room for the keyboard, with the result that the TableView was too large, and wound up clipped. So I shrank the popover... and now the TableView is shrinking itself when I reload it's data (which I have to do when a user types in a search key). Please note that the error only shows after I reloadData the tableView; and instead of clipping, now that it's shrinking it's 'band boxing' at the top and bottom.
When I query against the frame data, the tableView oddly enough appears to maintain it's height. What that means I don't know. If I dismiss the popover and represent it, it doesn't fix the issue (I think the popover winds up being larger?), but when I recall the keyboard it does (popover shrinks back to the right height). (I don't want to try and do that as a fix because that'll just be annoying for a user whose actively typing).
Edit:
If it matters, the only autolayout I've applied is to the UITableView; it's been given a fixed width, and a height. No X or Y data, which might have been a mistake, except I generate an error when I try to reference the superview -- probably because the popover doesn't create a superview until I try to present it?
Edit: Requested code (Sorry it's such a large and ugly block):
-(void)setupViewsAfterRotation
{
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
[self.searchTable.view removeFromSuperview];
self.popover=[[UIPopoverController alloc] initWithContentViewController:self.searchTable];
self.navigationItem.leftItemsSupplementBackButton=YES;
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"Search"
style:UIBarButtonItemStylePlain
target:self
action:@selector(presentPopover)];
[self setupPortraitConstraints];
//NSLog(@"Intrinsic size data: width: %f and height: %f",self.searchTable.view.intrinsicContentSize.width, self.searchTable.view.intrinsicContentSize.height);
//NSLog(@"Runtime size data: width: %f and height: %f",self.searchTable.view.frame.size.width, self.searchTable.view.frame.size.height);
} else {
[self.popover dismissPopoverAnimated:NO];
self.popover=nil;
self.navigationItem.leftBarButtonItem=nil;
[self.view addSubview:self.searchTable.view];
[self setupLandscapeConstraints];
}
}
-(void)setupLandscapeConstraints
{
if (self.tableViewConstraints) {
[self.view removeConstraints:self.tableViewConstraints];
self.tableViewConstraints=nil;
}
NSMutableArray *landscapeConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"|[tableView(==256)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];
[landscapeConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topLayoutGuide][tableView]|"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view,
@"topLayoutGuide":[self topLayoutGuide]
}]];
self.tableViewConstraints=landscapeConstraints;
[self.view addConstraints:self.tableViewConstraints];
}
-(void)setupPortraitConstraints
{
if (self.tableViewConstraints) {
[self.view removeConstraints:self.tableViewConstraints];
self.tableViewConstraints=nil;
}
NSMutableArray *portraitConstraints;
if (self.keyboardHeight) {
NSLog(@"Height set to 612");
portraitConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tableView(==612)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];
[self.popover setPopoverContentSize:CGSizeMake(256, 612) animated:YES];
}
else{
NSLog(@"Height set to 768");
portraitConstraints=[[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tableView(==768)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}] mutableCopy];
[self.popover setPopoverContentSize:CGSizeMake(256, 768) animated:YES];
}
[portraitConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"[tableView(==256)]"
options:0
metrics:nil
views:@{@"tableView": self.searchTable.view}]];
self.tableViewConstraints=portraitConstraints;
[self.searchTable.view addConstraints:self.tableViewConstraints];
}
Upvotes: 2
Views: 2774
Reputation: 12231
Set the content size for your popover to limit the popover's view area.
You can do this by the following ways:
From Apple's Documentation:
Popovers normally derive their size from the view controller they present. However, you can change the size of the popover by modifying the value in the popoverContentSize property or by calling the setPopoverContentSize:animated: method. The latter approach is particularly effective if you need to animate changes to the popover’s size. The size you specify is just the preferred size for the popover’s view. The actual size may be altered to ensure that the popover fits on the screen and does not collide with the keyboard.
From Apple's documentation regarding popoverContentSize property:
Changing the value of this property overrides the default value of the current view controller. The overridden value persists until you assign a new content view controller to the receiver. Thus, if you want to keep your overridden value, you must reassign it after changing the content view controller.
Upvotes: 2