How to catch select event of table cell
I have 开发者_运维问答an UIViewController where I have placed some single table cells. Most of them are just a nice way to display data which does not allow any interaction. But now I added a cell which needs to be clicked to open another view.
How can I see that the cell was clicked? How do I implement that?
You need to implement the delegate method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//where indexPath.row is the selected cell
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
See also docs - UITableViewDataSource Protocol
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
//where indexPath.row is the selected cell
[self performSegueWithIdentifier:@"showMobileDetail" sender:indexPath];
}
精彩评论