Iphone 在尝试检索选定的表单元格时,如何正确实现-(NSIndexPath*)indexPathForSelectedRow

Iphone 在尝试检索选定的表单元格时,如何正确实现-(NSIndexPath*)indexPathForSelectedRow,iphone,uitableview,delegates,Iphone,Uitableview,Delegates,我的表视图有一个委托,希望能够在用户选择表视图中的单元格时触发操作 indexPathForSelectedRow的方法-(NSIndexPath*)是如何正确实现的?如果您正确设置了表委托(有关更多信息,请参阅Apple的AdvancedTableViewCells教程或任何数量的优秀教程),那么您可以按照Apple的协议实现此方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

我的表视图有一个委托,希望能够在用户选择表视图中的单元格时触发操作


indexPathForSelectedRow的方法-(NSIndexPath*)是如何正确实现的?

如果您正确设置了表委托(有关更多信息,请参阅Apple的
AdvancedTableViewCells
教程或任何数量的优秀教程),那么您可以按照Apple的协议实现此方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{   

    // in here you can do stuff based on which cell they selected
    // at a certain index path, like the examples below

    // get value for which row was pressed
    int row = indexPath.row;

    // or find cell that was just pressed and grab handle for the new info that needs to be put on it
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    UIButton *newButton;
    newButton = (UIButton *)[cell viewWithTag:4];

    UILabel *newLabel;
    newLabel = (UILabel *)[cell viewWithTag:5];

    // or de-select the row per Apple's Human Interface Guidelines 
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}   
这些只是一般性的例子,但希望它们能为您提供一些关于这个主题的信息