作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
注意:我只在模拟器上测试过。
我想在代码中添加目标操作,而不是在 Interface Builder 中将其连接为 IBAction。
theButton
在左上角的导航栏上,在 IB 中创建。
步骤:
将 theButton
声明为 IBOutlet 并在 IB 中连接它。
在 viewDidLoad
中添加:
self.theButton.target = self;
self.theButton.action = @selector(theAction);
我正在通过此测试 theAction
:
- (void)theAction {
NSLog(@"theAction called");
//do some other stuff
}
当我在模拟器中点击 theButton
时,没有任何反应。我根本没有看到 NSLog 语句。
我错过了什么?
最佳答案
您是否已将操作连接到界面构建器中的按钮?
如果不是,您应该在 .h 文件中声明该操作
-(IBAction)theAction;
更改 .m 文件上的操作名称
-(IBAction)theAction{
}
然后将操作精细地连接到界面构建器中的按钮。
关于iphone - 轻按 UIBarButtonItem 时未调用操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6407242/
注意:我只在模拟器上测试过。 我想在代码中添加目标操作,而不是在 Interface Builder 中将其连接为 IBAction。 theButton 在左上角的导航栏上,在 IB 中创建。 步骤
我是一名优秀的程序员,十分优秀!