且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在按钮上单击tableViewController

更新时间:2023-01-01 17:13:26

id findAncestor(UIView *view, Class class) {
    while (view && ![view isKindOfClass:class])
        view = [view superview];
    return view;
}

- (void)buttonOfCellClicked:(UIButton *)button
{
    UITableViewCell *cell = (UITableViewCell *)findAncestor(button, [UITableViewCell class]);
    UITableView *table = (UITableView *)findAncestor(cell, [UITableView class]);
    NSIndexPath *path = [table indexPathForCell:cell];
    if (!path)
        return;
    Person *person = [personsArr objectAtIndex:path.row];
    // do whatever with person
}