2013-08-10 2 views
2

У меня есть табличный вид (без прокрутки) внутри UIPopoverController, который имеет 4 ячейки. И иногда он должен иметь дополнительную ячейку (1 макс). Если я оживляю добавление и вычитание этой ячейки, могу ли я также обновить высоту popover?Обновление высоты uipopover при добавлении ячейки

Вот как я создаю вид поповер таблицы:

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

Код все " работает "отлично, но когда я добавляю дополнительную ячейку, она отключается из-за отсутствия прокрутки моего контроллера popover. Как я могу это обновить?

+0

почему вы хотите обновить высоту UIPopOverView ?? даже UITableView уже имеет scrollView, поэтому tableView настраивает его самостоятельно. :) – iPatel

+0

У меня прокрутка отключена, она просто подходит для всего приложения. Мне нужно изменить высоту, потому что часть моей последней ячейки отключена и без прокрутки выглядит ужасно. – lostAstronaut

ответ

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]; 
} 
+0

В итоге я сделал что-то другое, но это поставило меня в правильном направлении. – lostAstronaut

Смежные вопросы