开发者

On iPhone Objective C, How do you catch the event of a row in a table being selected?

开发者 https://www.devze.com 2022-12-23 12:06 出处:网络
I have a data tab开发者_如何学Gole filled with text in each table row.How do I attach to the event for the row being selected and know which row was selected?The object that is the UITableViewDelegate

I have a data tab开发者_如何学Gole filled with text in each table row. How do I attach to the event for the row being selected and know which row was selected?


The object that is the UITableViewDelegate for your UITableView (usually the view controller that owns the table view) just needs to implement the tableView:didSelectRowAtIndexPath: method. You can get the column and row from the parameter passed in. Be sure to conform to the Apple HIG and deselect the row in this method.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];

    // do something here

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


Your UITableViewDelegate should implement the tableView:didSelectRowAtIndexPath: which will be called whenever a row is selected

You can get the section and row that were selected form the indexPath passed into the method with

[indexPath row];
[indexPath section];

See more under the UITableViewDelegate protocol reference

0

精彩评论

暂无评论...
验证码 换一张
取 消