UITableViewCell与UIButton

UITableViewCell与UIButton

本文介绍了UITableViewCell与UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UITable其中包含一些UIButtons。我想要一个使用标签的方法。

I have UITable which contains some UIButtons. I would like a way to use the label.

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

The problem I have is that I need two tag labels, one for retrieving the cell in tableviewCellWithReuseIdentifier and configureCell.

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

Until recently I have been using the UIButton.title to determine which row in the table I selected. The (invisible) text was the row number.

现在我需要使用标题来显示一些可见文本。如何仍然可以找到按下哪一行?

Now I need to use the title for some visible text. How can I still find which row was pressed?

当我按下按钮以外的区域时,通常的 didSelectRowAtIndexPath 困难的部分是,我想捕获的UIButton(它调用自己的选择器)的行,我一直在标题发现。现在我需要别的东西。

When I press the area outside the button the usual didSelectRowAtIndexPath is called. The hard part is that I want to capture both the UIButton (which calls its own selector) and the row, which I had been finding out from the title. Now I need the title for something else.

推荐答案

我使用这样的东西。这将得到tableview中的索引路径。

I use something like this. This will get you the indexpath in the tableview.

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

    // do something
}

这篇关于UITableViewCell与UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:22