在cell中先:
[cell.ClassifyButton addTarget:self action:@selector(classAction:event:) forControlEvents:UIControlEventTouchUpInside];
实现点击方法:
-(void)classAction:(UIButton *)button event:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
CGPoint point = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
cityModel *Cmodel = self.listArray[indexPath.row];
PersonViewController *person = [[PersonViewController alloc] init];
person.personId = Cmodel.user[@"id"];
[self.navigationController pushViewController:person animated:NO];
}

本文介绍了一种在UITableView的单元格中的按钮上设置点击事件的方法。通过为按钮添加目标和动作,可以在点击按钮时获取到当前点击所在单元格的位置信息,并进一步跳转到新的视图控制器,展示了如何在iOS应用中有效处理UITableView中单元格内部元素的交互。
55

被折叠的 条评论
为什么被折叠?



