当我点击UIButton时,我试图找出UITableView中当前选择的单元格

时间:2023-02-10 21:08:18

I have 2 UITableViews. When I click the UIButton outside of either UITableView I'm trying to determine which cells are selected in each tableview.

我有2个UITableViews。当我单击UITableView外的UIButton时,我正在尝试确定在每个tableview中选择了哪些单元格。

Anyone have a good way of doing this? Would I loop over the cells to determine which cell is currently selected? Or is there already a method that can tell me?

任何人都有这样做的好方法?我是否会遍历单元格以确定当前选择的单元格?或者是否有一种方法可以告诉我?

Thanks a bunch!

谢谢你!

1 个解决方案

#1


1  

You can use this method:

您可以使用此方法:

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

}

Take a look at UITableViewDelegate Protocol Reference

看看UITableViewDelegate协议参考

UITableViewDelege Reference

EDIT: When the user select a row in one of your tables you can get it using this method and a couple of variables for the table and the cell and then you can pass what you got as soon as the user tap on your button.

编辑:当用户在其中一个表格中选择一行时,您可以使用此方法获取该行,并为表格和单元格选择一些变量,然后您可以在用户点击按钮后立即传递所获得的内容。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    thisIsMyTable = tableView;
    thisIsTheSelectedRow = indexPath.row;
    }

- (void)buttonTapped {
    // Do what you need
}

#1


1  

You can use this method:

您可以使用此方法:

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

}

Take a look at UITableViewDelegate Protocol Reference

看看UITableViewDelegate协议参考

UITableViewDelege Reference

EDIT: When the user select a row in one of your tables you can get it using this method and a couple of variables for the table and the cell and then you can pass what you got as soon as the user tap on your button.

编辑:当用户在其中一个表格中选择一行时,您可以使用此方法获取该行,并为表格和单元格选择一些变量,然后您可以在用户点击按钮后立即传递所获得的内容。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    thisIsMyTable = tableView;
    thisIsTheSelectedRow = indexPath.row;
    }

- (void)buttonTapped {
    // Do what you need
}