我创建了一个具有自定义UITableViewCell的TableView.每个tableview行都有一个按钮.现在我想知道单击按钮时的行号,以便我知道单击了哪个行按钮.我尝试过在堆栈上找到的一些东西,但没有任何工作.
我试过这段代码 - :
-(void)button1Tapped:(id)sender
{
UIButton *senderButton = (UIButton *)sender;
UITableViewCell *buttonCell = (UITableViewCell *)[senderButton superview];
UITableView* table = (UITableView *)[buttonCell superview];
NSIndexPath* pathOfTheCell = [table indexPathForCell:buttonCell];
NSInteger rowOfTheCell = [pathOfTheCell row];
NSLog(@"rowofthecell %d", rowOfTheCell);
}
Run Code Online (Sandbox Code Playgroud)
但这也行不通.
谢谢你的协助.
我有一个UITableView,我已经为其创建了一个自定义的UITableViewCell.tableview中的每一行都有一个按钮.我想知道单击按钮时的节号,以便我知道单击了哪个部分按钮.我已经尝试过在堆栈上找到的一些东西,但没有任何工作.
UIButton *b = sender;
NSIndexPath *path = [NSIndexPath indexPathForRow:b.tag inSection:0];
NSLog(@"Row %d - Section : %d", path.row, path.section);
Run Code Online (Sandbox Code Playgroud)