2015-04-06 60 views
0

我在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

回答

0

您可以使用[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]; 
} 
0

聲明細胞對給定indexPath

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

然後訪問圖像查看

cell.imageView