2

4 つのセルを持つ UIPopoverController 内にテーブル ビュー (スクロールなし) があります。また、追加のセル (最大 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);
}

次に、私の方法の1つに、テーブルを変更する必要がある場合の次のコードがあります。

[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 に答える