UIPopoverController顶部的UITableViewController不可见

时间:2014-01-07 18:45:00

标签: ios uitableview uipopovercontroller

我有一个UITableViewController被用作UIPopoverController内的内容视图控制器。不幸的是,桌面视图内容正在被截止顶部,我可以尝试向下滚动并看到它,尽管它反弹回顶部。有点像这样:

Table view content starts up here (what I want in the middle of the popover)

    ---------------
    |  bottom     |
    |   of        |
    |   table     |
    |   view      |
    ---------------

我的tableView是否超出UIPopoverController的首位?

2 个答案:

答案 0 :(得分:1)

由您来设置UIPopoverController的popoverContentSize以适应其内容视图控制器的视图。

答案 1 :(得分:1)

使用它来设置popOverController的contentSize

//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);

Ray's tutorial复制,我现在用于我的应用程序:)