当用户点击一个单元格时,我想更新我的UITableView
;包括这个已点击的单元格的内容。最简单的方法是更新内部参数,然后调用[self.tableView reloadData];
。
然而,reloadData
立即停止了我所点击的单元格的漂亮的蓝色->无选择动画.
是否有一种(标准的)方法来更新我的表格单元格而不停止被点击的单元格的动画?
注意:在这种情况下,我不添加或删除单元格;我只想更改内容(例如,启动一个活动指示器,或更改标签的颜色)。
发布于 2013-08-24 04:26:53
在这种情况下,您只需获取指向所有可见单元格的指针并更新它们。就像这样:
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSArray* visibleCells = [tableView indexPathsForVisibleRows];
for (NSIndexPath* indexPath in visibleCells)
{
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
[self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content...
}
}
如果您想更新其他单元格内容,可以使用以下内容:
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
[self updateCell:cell atIndexPath:indexPath]; // Your method, which updates content...
}
因此,您的单元格将始终显示正确的内容。
关于创建内容:
- (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];
[self createContentForCell:cell atIndexPath:indexPath]; // so here to create content or customize cell
}
return cell;
}
发布于 2013-08-24 07:32:46
或者您可以简单地延迟表数据的重新加载,例如:Delay reloadData on UITableView
https://stackoverflow.com/questions/18418466
复制