ios - 如何从 Storyboard 静态单元格中的 UIButton 触发 IBAction?

标签 ios uibutton uitableview ibaction

我有一个带有 UITableViewController 的 Storyboard。在此 Controller 中,我有静态单元格,其中之一是 UITableViewCell 的子类。在 IB 中,我向此静态单元添加了一个 UIButton,并将其连接到 UITableViewCell 子类中的 IBAction。然而,IBAction 永远不会被调用。为什么这不起作用?如何实现单元格内的按钮通过 IB 触发事件的所需行为?

.h

#import <UIKit/UIKit.h>

@interface BSWorkoutsCell : UITableViewCell

@property (nonatomic, weak) IBOutlet UIButton *button;
@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *buttons;

- (IBAction)tapButton:(id)sender;
@end

.m

- (IBAction)tapButton:(id)sender{
    if (!_buttonsHidden){
        [self animateHideButtons:(UIButton *)sender];
        _buttonsHidden = YES;
    }
}

图片

enter image description here

enter image description here

最佳答案

我意识到 UITableViewCell 在 IB 中未选中User Interaction Enabled。这使得其中的任何 subview 都无法交互,因此按钮实际上没有被按下,并且 IBAction 没有被调用。

一旦我选中该框,一切就正常了。

关于ios - 如何从 Storyboard 静态单元格中的 UIButton 触发 IBAction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17713595/

相关文章:

objective-c - 如何在不使用 "tel://123"url 的情况下在 iphone 中打开电话应用程序

web-applications - 如何为 Web 应用程序设置离线 list 以在 iOS 的 Safari 中运行?

ios - 如何使图像方向旋转 270 度 (swift3)

ios - 如何限制按钮的文本

ios - 如何在 iOS 上构建大版本的信息按钮?

php - 如何在 Swift 的 iOS 设置中创建类似 UITableView 的选择选项?

ios - 应用图层蒙版后我的图像按比例缩小

UIButton 上的 iOS 悬停效果

ios - UITableViewCell Storyboard 注册依赖于初始 View Controller ?

ios - 在 ParallaxBlur Controller 中刷新 TableView