If you are using code to directly add controls (such as Uilabel, UIButton, etc.) to the UITableView cell,
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
Custom code
return cell;
}
After this function, when you click on the cell, you want to know exactly what line is clicked, and then you can get the number of clicks in the following code.
UITableViewCell *cell = (UITableViewCell *) [btn Superview];
Nsindexpath *indexpath = [_mytableview Indexpathforcell:cell];
NSLog (@"Indexpath is =%i", indexpath.row);
Note: BTN is a button,_mytableview that you add to the cell by way of code, which is an associative variable of uitableview.
If you are creating a new, xib Way to create an inherited UITableViewCell. Xib (for example, shopcell.xib) file to add the way to the original UITableView cell, Using this method is not to get the number of rows that are clicked on the cell, that is, you do not know where the clicked cell is the first line.
You can also use the code above, but modify it a little bit:
UITableViewCell *cell = (UITableViewCell *) [[[Btn Superview] superview] superview];
Nsindexpath *indexpath = [_mytableview Indexpathforcell:cell];
NSLog (@"Indexpath is =%i", indexpath.row);
Explanation: [btn Superview] in the first code is the contentviewof Shopcell, and the second superview is the cellof Shopcell itself, The third superview is the cellof UITableView, take care not to confuse it.
Know the row and then use row to determine which row is the cell
Nsindexpath *index1 = [Nsindexpath indexpathforitem:row insection:0];
UITableViewCell *cell1 = [_mytableview cellforrowatindexpath:index1];
Customize the button in the cell to get the cell's Indexpath