Igbalajobi Jamiu
Igbalajobi Jamiu

Reputation: 261

iOS Objective-C IBAction runs the code in method twice

I tried to run this method of code

- (IBAction)signInButton:(id)sender {
      NSLog(@"Run Action %@", @"Here");
 }

The result of this code log the "Run Action Here" twice in the console.

I initially loaded all my project import file (.m and .h) in one header file "Loader.h", I taught this was the cause, but I still experience the same issue even after I dissembled the header file.

Same Issue happens on other view controller.

What am I doing wrong ?

Thanks in advance.

Upvotes: 0

Views: 1034

Answers (2)

Anton Kukoba
Anton Kukoba

Reputation: 293

This seems to be some problem with the logging. It indeed logs twice from IBAction handlers. I put NSAlert, to make sure it's called twice, but it was called once, nevertheless the log was printed twice in the console.

Upvotes: 0

Caleb
Caleb

Reputation: 125007

It sounds like you've connected the action to your button or other UI element for two different events. For example, if you connect it to both the touch down and touch up events, a single tap of the button will trigger the action twice.

One thing you can do to diagnose the problem is to control-click on the view controller containing the action in your nib or storyboard and look at the Received Actions section near the bottom of the resulting popup. You'll likely see your action connected twice.

Another option is to set a breakpoint in the action and take a look at the sender parameter each time you hit the breakpoint. This will show you what object is triggering the action each time.

Upvotes: 1

Related Questions