我有一个带工具栏的xib,我有两个全部用IB制作的按钮。 我可以将我的插座连接到按钮,但是当我点击它们时,方法不会被触发? 那是为什么?
在我的标题文件中,我有这个:
@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelEntry;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *saveEntry;
-(IBAction) cancelEntry:(id) sender;
-(IBAction) saveEntry:(id) sender;
在我的.m文件中,我得到了这个:
-(IBAction) cancelEntry:(id) sender {
NSLog(@"cancel");
}
-(IBAction) saveEntry:(id) sender {
NSLog(@"save");
}
所有编译都应该按照它应该但在单击按钮时日志中没有任何内容。 我该怎么办才能让它发挥作用?
答案 0 :(得分:4)
听起来您将插座连接到按钮,但没有将按钮连接到操作。
UIBarButtonItem
。您应该使用(id)
,而不是将(UIBarButtonItem *)
用于您的IBAction。这将阻止您将不同的对象类型连接到那些IBActions。