2

我在 UIPopoverController 中有一个表格视图(不滚动),它有 4 个单元格。有时它需要有一个额外的单元格(最多 1 个)。如果我正在为该单元格的加减制作动画,我可以更新弹出框的高度吗?

这是我创建弹出表视图的方法:

- (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];

代码都“工作正常”,但是当我添加额外的单元格时,由于我的弹出框控制器的非滚动特性,它被切断了。有什么办法可以更新吗?

4

1 回答 1

2

试试这个对我有用

-(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];
}
于 2013-08-10T05:47:38.620 回答