我有一个带有 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;
}
}
图片
最佳答案
我意识到 UITableViewCell 在 IB 中未选中User Interaction Enabled
。这使得其中的任何 subview 都无法交互,因此按钮实际上没有被按下,并且 IBAction
没有被调用。
一旦我选中该框,一切就正常了。
关于ios - 如何从 Storyboard 静态单元格中的 UIButton 触发 IBAction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17713595/