如何从单元格访问UIImageView

问题描述:

我在tableView的自定义单元格中有一个imageView。我通过使用viewWithTag来访问cellforRowAtIndexPath中的imageView。但是我怎样才能在另一个函数中访问imageView?像didSelectRowAtIndexPath如何从单元格访问UIImageView

+3

你不应该想。使用数据模型。如果您有自定义单元格,则不应使用标记,请使用属性。 – Wain 2015-04-06 09:35:46

+0

@是什么意思是使用数据模型? – marosoaie 2015-04-06 09:38:26

+0

您有一组数据,告诉您如何配置单元格,即您的数据模型和数据的真实来源。不应该查询单元以获取该信息。 – Wain 2015-04-06 09:44:46

您可以使用[tableView cellForRowAtIndexPath:indexPath]接入小区,然后从细胞可以访问它的使用viewWithTag子视图(内容)AS-

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // access the cell for selected cell 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    // from cell using viewWithTag:image view's tag access imageView 
    UIImageView *imageView = [cell viewWithTag:CELL_IMAGE_VIEW_TAG]; 
} 

声明细胞对给定indexPath

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 

然后访问图像查看

cell.imageView