当用户点击某个单元格时,我想更新我的UITableView
;包括这个被点击的单元格的内容。最简单的方法是更新内部参数然后调用[self.tableView reloadData];
.
然而,reloadData
立即停止我点击的单元格的漂亮的蓝色->无选择动画。
有没有一种(标准)方法可以更新我的表格单元格而不停止点击单元格的动画?
请注意,在这种情况下,我不会添加或删除单元格;我只想更改内容(例如启动活动指示器,或更改标签的颜色。)
在您的情况下,您只需获取指向所有可见单元格的指针并更新它们。像这样的事情:
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)