在移动行之后,我更改了与单元格关联的biz的lineandPin编号。如果再次调用cellForRowAtIndexpath,那么一切都会正常进行。
这是我的代码
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSMutableArray * mutableBusinessBookmarked= self.businessesBookmarked.mutableCopy;
Business *bizToMove = mutableBusinessBookmarked[sourceIndexPath.row];
[mutableBusinessBookmarked removeObjectAtIndex:sourceIndexPath.row];
[mutableBusinessBookmarked insertObject:bizToMove atIndex:destinationIndexPath.row];
self.businessesBookmarked=mutableBusinessBookmarked;
[self rearrangePin];
[tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
[self.table reloadData];
}
moveRowAtIndexPath
[tableView moveRowAtIndexPath...
似乎没有做任何事情。无论我是否调用它,行都会被移动。self.table reloadData
.,但仍未调用cellForRowAtindexpath
发布于 2013-01-20 10:22:38
我建议将单元配置逻辑移到一个单独的方法中。然后在moveRowAtIndexPath
中,您可以通过直接调用此方法来更新可见单元格。例如:
- (void)configureCell:(UITableViewCell *)cell
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
// Get data for index path and use it to update cell's configuration.
}
- (void)reconfigureVisibleCells
{
for (UITableViewCell *cell in self.tableView.visibleCells) {
[self configureCell:cell];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellIdentifier"];
[self configureCell:cell];
return cell;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
// Update data model. Don't call moveRowAtIndexPath.
[self reconfigureVisibleCells];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self configureCell:cell];
}
以下是一些额外的评论:
仅当表格视图需要显示新的单元格时,才会调用
cellForRowAtIndexPath
。moveRowAtIndexpath
是合适的。您的情况正好相反,即UI正在将更改传播到您的数据模型。因此,您不会在cellForRowAtIndexPath
.之后调用moveRowAtIndexPath
.
willDisplayCell
,因为在某些情况下,表视图将覆盖您的自定义设置https://stackoverflow.com/questions/14417524
复制相似问题