9
如果我爲段的第一個單元調用reloadRowsAtIndexPaths,前面的段爲空,而上面的段不爲空,我得到一個奇怪的動畫故障(即使我指定「UITableViewRowAnimationNone」)重載單元從幻燈片上一節下來..UITableView reloadRowsAtIndexPaths圖形故障
我試圖簡化儘可能的例子:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0)
return 1;
else if (section == 1)
return 0;
else if (section == 2)
return 3;
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = @"Text";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *editedCell = [[NSArray alloc] initWithObjects:indexPath, nil];
//[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:editedCell withRowAnimation:UITableViewRowAnimationNone];
//[self.tableView endUpdates];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"Section";
}
其實你可以註釋掉的最後一個方法,但它提供了一個更好的理解這個問題。
這是一個很好的解決方案,反正是從奇怪的行爲reloadRowsAtIndexPaths一個錯誤,或者我只是以錯誤的方式使用它? – Fr4ncis
@ Fr4ncis,我不確定。重新加載單元格表格視圖可能需要將它們從視圖層次結構中添加/刪除,重建其子視圖或其他內容 - 這取決於所有這些轉換是如何在內部實現的 – Vladimir
謝謝,您的解決方案乾淨且結構良好。 – jalopezsuarez