Я пытаюсь иметь UITableViewCell
, который при прокрутке прокручивается до предварительного просмотра.обновление UITableViewCell height в iOS7
Мне удалось это сделать, с булевыми значениями - то есть - в cellForRowAtIndexPath
Я изменяю булевой массив всех ячеек перед текущей ячейкой.
В iOS8 он отлично работает - проблема в том, что в iOS7 heightForRowAtIndexPath
вызывается только на TableView Load.
Я знаю, что я могу сделать:
[tableView beginUpdates];
[tableView endUpdates];
Но я не могу сделать это внутри cellForRowAtIndexPath
(он выходит из строя)
Где я могу запустить?
Код:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[collapsedChapters objectAtIndex:indexPath.row] boolValue] == YES)
{
return 73;
}
//else - calculate
return 200; //the number is actually calculated - but simplifying
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell =[self generateChapterCell:tableView indexPath:indexPath];
[self handleLastVisible];
return cell;
}
- (void)handleLastVisible
{
NSInteger lastVisibleChapter = [self getLastVisibleRowOfSection:self.tableView section:chaptersSectionNum];
if (lastVisibleChapter > lastViewedChapter) //should work for -1 and 9999 as well
{
lastViewedChapter = lastVisibleChapter;
}
NSInteger firstVisibleChapter = [self getFirstVisibleRowOfSection:self.tableView section:chaptersSectionNum];
if (firstVisibleChapter == -1)
{
//we are before - don't touch
return;
}
NSNumber* yesObj = [NSNumber numberWithBool:YES];
//in case of 9999 - we will stop at the end of the for loop - it's OK
for (int i=0; i < [collapsedChapters count]; i++)
{
if (i == firstVisibleChapter)
{
break;
}
if ([[collapsedChapters objectAtIndex:i] boolValue] == NO)
{
[chapterFirstCollapse replaceObjectAtIndex:i withObject:yesObj];
}
[collapsedChapters replaceObjectAtIndex:i withObject:yesObj];
}
}
Фактически 'heightForRowAtIndexPath' следует вызывать каждый раз, когда ячейка будет отображаться. Если он не работает на iOS7, вы, должно быть, сделали что-то неправильно – Lefteris