简体   繁体   English

Mac Catalyst 项目中未调用 IBAction

[英]IBAction not called in Mac Catalyst project

I have some toolbar buttons in an Interface Builder .xib file, but clicking them does not call their corresponding IBAction methods in my view controller.我在 Interface Builder .xib 文件中有一些工具栏按钮,但是单击它们不会在我的视图控制器中调用它们相应的 IBAction 方法。

I know the view controller is connected to the nib, because test code like this in the view controller has the expected result:我知道视图控制器连接到笔尖,因为视图控制器中这样的测试代码具有预期的结果:

self.saveButton.title = @"foo";

When I click the button, it shows the selected state, but then nothing happens when I release it.当我单击按钮时,它显示选定状态,但是当我释放它时没有任何反应。 The method definition looks like this...方法定义看起来像这样......

- (IBAction)save:(UIButton *)sender;

...and I see the connection in the Connections Inspector in Interface Builder. ...我在 Interface Builder 的 Connections Inspector 中看到了连接。 I have other buttons that work fine, and I don't see what's different about this one.我还有其他按钮可以正常工作,但我看不出这个按钮有什么不同。

I had the wrong type for the sender argument in the IBAction method.我在 IBAction 方法中的 sender 参数类型错误。 I somehow had this:我不知何故有这个:

- (IBAction)save:(UIButton *)sender;

But since a bar button item is calling this, it should be:但是由于条形按钮项正在调用它,它应该是:

- (IBAction)save:(UIBarButtonItem *)sender;

After updating the code, I had to unlink and relink the button in Interface Builder.更新代码后,我不得不取消链接并重新链接 Interface Builder 中的按钮。 Then it worked!然后它起作用了!

I've been using this code for years on iOS with no problem, but apparently the Mac Catalyst platform is less permissive for an error like this.我多年来一直在 iOS 上使用此代码没有问题,但显然 Mac Catalyst 平台对此类错误的容忍度较低。

I haven't seen many Mac Catalyst issues posted yet, so hopefully this will help someone in the same situation.我还没有看到发布的很多 Mac Catalyst 问题,所以希望这会对处于相同情况的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM