如何在didSelectRowAtIndexPath中访问当前选定的单元格?

JaH*_*lia 65 iphone xcode objective-c ios

我想通过以下方法更改单元格的附件视图类型:didSelectRowAtIndexPath,即当选择行时我想更改附件视图类型,我可以在该方法中执行此操作吗?

Emp*_*ack 136

你可以像这样使用indexPathdidSelectRowAtIndexPath:方法获取单元格.

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)


Tej*_*der 6

在Swift 3.0中:您可以根据需要使用这两种方式

 let cell:UITableViewCell = tableView.cellForRow(at: indexPath) as UITableViewCell
Run Code Online (Sandbox Code Playgroud)

要么

let cell:CustomTableViewCell = tableView.cellForRow(at: indexPath) as! CustomTableViewCell
Run Code Online (Sandbox Code Playgroud)

快乐编码!!


Jha*_*iya 5

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
     UITableViewCell *myCell = [tableView cellForRowAtIndexPath:indexPath];
     // Access accessory View  as below.  
     UIView * myCellAccessoryView = myCell.accessoryView;
}
Run Code Online (Sandbox Code Playgroud)