Ios UIPopoverController顶部内的UITableViewController不可见
我有一个Ios UIPopoverController顶部内的UITableViewController不可见,ios,uitableview,uipopovercontroller,Ios,Uitableview,Uipopovercontroller,我有一个UITableViewController用作UIPopoverController中的内容视图控制器。不幸的是,表视图的内容被从顶部切掉了,我可以尝试向下滚动到很远的地方,然后看到它,尽管它会反弹到顶部。有点像这样: Table view content starts up here (what I want in the middle of the popover) --------------- | bottom | | of
UITableViewController
用作UIPopoverController
中的内容视图控制器。不幸的是,表视图的内容被从顶部切掉了,我可以尝试向下滚动到很远的地方,然后看到它,尽管它会反弹到顶部。有点像这样:
Table view content starts up here (what I want in the middle of the popover)
---------------
| bottom |
| of |
| table |
| view |
---------------
我的
表格视图
远高于UIPopoverController
的折叠是否有原因?由您设置UIPopoverController的popoverContentSize
以适应其内容视图控制器的视图。使用此设置popOverController的内容大小
//Calculate how tall the view should be by multiplying
//the individual row height by the total number of rows.
NSInteger rowsCount = [_colorNames count];
NSInteger singleRowHeight = [self.tableView.delegate tableView:self.tableView
heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
NSInteger totalRowsHeight = rowsCount * singleRowHeight;
//Calculate how wide the view should be by finding how
//wide each string is expected to be
CGFloat largestLabelWidth = 0;
for (NSString *colorName in _colorNames) {
//Checks size of text using the default font for UITableViewCell's textLabel.
CGSize labelSize = [colorName sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]];
if (labelSize.width > largestLabelWidth) {
largestLabelWidth = labelSize.width;
}
}
//Add a little padding to the width
CGFloat popoverWidth = largestLabelWidth + 100;
//Set the property to tell the popover container how big this view will be.
self.contentSizeForViewInPopover = CGSizeMake(popoverWidth, totalRowsHeight);
复制自,我现在正在将其用于我的应用程序:)