我在 UIPopoverController 中有一个表格 View (不滚动),有 4 个单元格。有时它需要一个额外的单元(最多 1 个)。如果我要为该单元格的加法和减法设置动画,我也可以更新弹出框的高度吗?
以下是我创建弹出表格 View 的方法:
- (void)createPopoverTable
{
//set up array
_arrayList = [NSMutableArray arrayWithObjects:@"one", @"two", @"three", @"four", nil];
//Make row selections persist.
self.clearsSelectionOnViewWillAppear = NO;
//View height
NSInteger rowsCount = [_arrayList count];
NSInteger singleRowHeight = [self.tableView.delegate tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSInteger totalRowsHeight = (rowsCount * singleRowHeight) + 20;
//View width
CGFloat largestLabelWidth = 0;
for (NSString *item in _arrayList) {
//check size of font using default label
CGSize labelSize = [item sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]];
if (labelSize.width > largestLabelWidth) {
largestLabelWidth = labelSize.width;
}
}
//some padding for the width
CGFloat popoverWidth = largestLabelWidth + 200;
//Tell popover the size
self.contentSizeForViewInPopover = CGSizeMake(popoverWidth, totalRowsHeight);
}
然后,在我的方法之一中,当表格需要更改时,我有以下代码:
[self.tableView beginUpdates];
//update the array
[_arrayList insertObject:@"Blue" atIndex:3];
//insert the row
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:3 inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
代码一切“工作”正常,但当我添加额外的单元格时,由于弹出窗口 Controller 的非滚动性质,它被切断。有什么办法可以更新吗?
最佳答案
试试这个对我有用的
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.contentSizeForViewInPopover = self.tableView.contentSize;
}
-(void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.popoverControllerContainer setPopoverContentSize:self.contentSizeForViewInPopover animated:YES];
}
关于ios - 添加单元格时更新 uipopover 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18158692/