小编Ale*_*hel的帖子

如何知道UITableView中Tableview单元格按钮上的indexPath /行?

我创建了一个具有自定义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)

但这也行不通.

谢谢你的协助.

iphone uitableview ios

6
推荐指数
1
解决办法
1万
查看次数

如何知道UITableView中Tableview单元格按钮上的节号?

我有一个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)

iphone uitableview ios

0
推荐指数
1
解决办法
2828
查看次数

标签 统计

ios ×2

iphone ×2

uitableview ×2