简体   繁体   中英

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.

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. 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. 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. 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.

I haven't seen many Mac Catalyst issues posted yet, so hopefully this will help someone in the same situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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