是否有可能通过标签更新iOS UITableView中的cell imageView?我赞赏其他方法可用,但我想尽可能使用标签。通过标签更新UITableView Cell imageView
我通过设置图像:
cell.imageView.image = [UIImage imageNamed:@"dinner.png"];
而在另一种方法,我可以得到由细胞(标签始终是唯一的):
NSInteger the_tag = ((UIView*)sender).tag;
UITableViewCell *updateCell = (UITableViewCell*)[tableView viewWithTag:the_tag];
是否有可能更新与此单元格方法?这不起作用:
updateCell.imageView.image = [UIImage imageNamed:@"lunch.png"];
编辑:
在反映,标签是坏的方法使用。您可以使用(这将给你行和部分,如果你有一分段表):
- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
NSLog(@"Tapped Row %@", indexPath);
UITableViewCell *cell = [self->tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:@"lunch.png"];
}
为什么你更喜欢使用标签?它很脆弱,在这种情况下它破坏了封装。 – Abizern
我认为你需要放置[self.tableView beginUpdates];在你的代码和[self.tableView endUpdates]之前;在代码后面,强制TableView更新其内容。 –
我同意,标签是一个不好的方法!更新了我的答案。 – Colin