【问题标题】:Send UIButtons touch down to the table?将 UIButtons 发送到桌面?
【发布时间】:2012-03-21 10:22:37
【问题描述】:

我在 .xib 的自定义单元格中的三列结构中有三个按钮

看图:

我还有两个类,一个包含列表,第二个包含单元格我设法注销了属于该单元格的类中按钮的触摸,但我也想知道他们是否触摸我想让 didSelectRowAtIndexPath 触发的 firstColumnButton。

我的最终目标是触发 didSelectRowAtIndexPath,找出哪个单元格已被按下,该单元格中的哪个按钮,以便用户可以转到他们按下的正确内容。

在 ListController.m 中:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSLog(@"Pressed on the table");
    if(cell.pressedButtonInColumnOne == YES){
            NSLog(@"Pressed button one in column one");
    }
}

现在第一个 NSLog 根本没有触发。

CategoryCell.m 中只有这个

 - (IBAction)pressedFirstColumnButton:(id)sender {
     NSLog(@"pressed first button in category cell");
 }

如果我在 IB 中将按钮向上移动,则表格会做出反应,但按钮不会被按下。

【问题讨论】:

    标签: objective-c ios ipad ios4


    【解决方案1】:

    你不应该继承 UITableViewCell 并在这个子类中定义你需要执行的任何方法吗?

    【讨论】:

    • 我对此很陌生,但是我有一个 UITableViewCell 的子类,即 CategoryCell,但是如何定义子类中执行的方法?
    【解决方案2】:

    答案没有解决,但我做了一个解决方法,为按钮制作了一个选择器,然后把代码放在那里,

    cell.secondColumnButton.tag = guideColumnTwo.GuideID.intValue;
    [cell.secondColumnButton setTitle:guideColumnTwo.Name forState:UIControlStateNormal];
    [cell.secondColumnButton addTarget:self action:@selector(whichButtonDidMasterPressed:)    
                     forControlEvents:UIControlEventTouchUpInside];
    

    我将 buttonLabel 设置为城市并用 id 标记按钮。

    如果有人真的解决了这个问题,那就太好了。

    制作的

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    

    方法没用。

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2018-07-18
      • 2020-09-06
      • 1970-01-01
      相关资源
      最近更新 更多