带有UIButton的UITableViewCell

Joh*_*ith 2 iphone cocoa-touch uitableview

我有UITable,其中包含一些UIButtons.我想用一种方法来使用标签.

我遇到的问题是我需要两个标签标签,一个用于检索tableviewCellWithReuseIdentifier和configureCell中的单元格.

直到最近,我一直在使用UIButton.title来确定我选择的表格中的哪一行.(不可见)文本是行号.

现在我需要将标题用于一些可见文本.我怎样才能找到按下哪一行?

当我按下按钮外的区域时,通常会调用didSelectRowAtIndexPath.困难的部分是我想捕获UIButton(它调用自己的选择器)行,我从标题中找到了.现在我需要其他东西的标题.

Mat*_*uch 9

我用的是这样的东西.这将获得tableview中的indexpath.

- (IBAction)buttonAction:(id)sender {
    UIButton *button = (UIButton *)sender;
    CGPoint buttonOriginInTableView = [button convertPoint:CGPointZero toView:tableView];
    NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:buttonOriginInTableView];

    // do something
}
Run Code Online (Sandbox Code Playgroud)

  • 我告诉过你我爱你吗? (4认同)