On iOS 6.1, UISwitch IBOutlet is always zero

I'm having problems working with UISwitch on a static UITableView . I have to restore the last state of a specific UISwitch when the application loads, but whenever I check the status of IBOutlet , it is zero. I tried to manually assign a variable, which also did not help.

That's what I'm doing:

SettingsController.h

 //IBOutlet connected correctly @property (strong, nonatomic) IBOutlet UISwitch *switch_displayDetail; 

SettingsController.m

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (!_switch_displayDetail) { NSLog(@"_switch_displayDetail is NIL"); //This is always displayed } //Switch is default to YES, I am trying to set it to NO //This line does nothing... [_switch_displayDetail setOn:[dataManager shouldDisplayDetail] animated:YES]; } 

In any case, when I check the status of _switch_displayDetail , it is zero. I call all methods of super initialization. Has anything changed on iOS 6.1?

[EDIT] Using a synthesized variable also does not work.

[EDIT 2] Found the problem to be a bug on Xcode or on iPhone Simulator. After testing on my iPod touch, the original algorithm worked fine.

I am getting away with this problem ...

+6
source share
3 answers

Thanks to everyone for your answers, but after almost putting it over, I tested my application on my iPod touch and it worked great. This seems like a bug on the iPhone Simulator, or most likely on Xcode (nothing new here). After resetting all the settings and data in the iPhone Simulator menu, he also worked there.

So, before you go crazy, test your application on a real device .

+1
source

I know first hand how difficult it is to upset these problems in the Twilight Zone. Obviously, there is too little information to diagnose, but I thought I would share how I approach debugging.

  • Override the installer for switch_displayDetail, there, write down the value, but also self
  • Then in viewWillAppear write the same thing

I feel like we're not talking about the same instance here. If I'm right, the installer will display the value, but not viewWillAppear . If I am wrong, then both will be zero, in which case you are not calling the correct init method, or your binding is incorrect in IB.

Only my two cents.

+1
source

First:

 @property (strong, nonatomic) IBOutlet UISwitch *switch_displayDetail; // should be a weak property 

And then you @synthesized your property?

-1
source

All Articles