【问题标题】:Tapping UIButton in custom cell doesn't call didSelectRowAtIndexPath在自定义单元格中点击 UIButton 不会调用 didSelectRowAtIndexPath
【发布时间】:2013-02-11 21:52:26
【问题描述】:

我在以编程方式添加的自定义单元格中有一个 UIButton:

UIButton *tag = [[UIButton alloc] init];
[tag addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

这是我的按钮处理程序:

-(void)buttonClicked:(id)sender
{
    UIButton *clickedButton= (UIButton*)sender;
    NSLog(@"Button tapped!", nil);
    self.tagTapped = YES;
    self.tagSelected = clickedButton.titleLabel.text;
}

按钮点击已注册,但我的主视图控制器中的 didSelectRowAtIndexPath 没有被调用。点击单元格中的其他位置有效,但点击按钮不会调用该方法。有什么想法吗?

【问题讨论】:

    标签: iphone xcode uibutton didselectrowatindexpath


    【解决方案1】:

    点击单元格中的其他位置有效,但点击按钮不会调用方法 (didSelectRowAtIndexPath)。

    这是设计使然。大多数人使用 UIButtons 来做一些不同于用户选择行时发生的事情。例如,在 Apple 的 Phone 应用程序中浏览语音邮件时,点击该行会启用 Call Back & Delete 按钮,同时点击该行的蓝色 AccessoryDe​​tailDisclosureButton 会显示一个新的 ViewController,其中显示语音邮件的日期和电话号码。

    【讨论】:

    • 谢谢,我刚刚做了一个委托方法来处理 UIButton 的调用。
    猜你喜欢
    • 2014-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 2013-08-12
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多