I am having some trouble while working with UISwitch on a static UITableView.
I have to restore the last state of a certain UISwitch when the App loads, but whenever I check the state of the IBOutlet, it is nil. I have tried to manually alloc the variable, which was of no help either.
Here is what I am 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];
}
Everywhere else when I check the state of _switch_displayDetail it is nil. I am calling all the super initialization methods.
Did anything change on iOS 6.1?
[EDIT] Using the synthesized variable does not work either.
[EDIT 2] Found the problem to be a bug on Xcode or on iPhone Simulator. After testing on my iPod touch, the initial algorithm worked perfectly.
I am going nuts with this problem…
Thanks everyone for your answers, but after almost giving up, I tested my App on my iPod touch and it worked perfectly. This looks like a bug on the iPhone Simulator or, much probably a bug on Xcode (nothing new here). After reseting all settings and data on the iPhone Simulator menu, it worked there too.
So, before going crazy, test your App on a real device.