I created a custom UIViewController.
@property (weak, nonatomic) NSArray *optionArray;
-(VCSelectionViewController*) getPopoverViewControllerForTextField:(UITextField*)textField {
UIViewController *buttonPopover = [[UIViewController alloc] init];
buttonPopover.optionArray = [OptionArray getLOCQualityArray]
But the optionArray value became nil in viewWillAppear for iOS9. It was working in iOS8. I have spent hours on this with no luck.
This is where I called the getPopoverViewControllerForTextField
method listed above.
-(void) displaySelectionPopover:(UITextField *)textField {
VCSelectionViewController *popoverViewController = [self getPopoverViewControllerForTextField:textField];
if(_masterPopoverController == nil && popoverViewController != nil){ //make sure popover isn't displayed more than once in the view
_masterPopoverController = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
}
[_masterPopoverController setPopoverContentSize:[popoverViewController getPopoverSize]];
_masterPopoverController.delegate = self;
[_masterPopoverController presentPopoverFromRect:textField.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
After I executed the code above, I can still see the optionArray values. optionArray still exists inside
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
But when it start executing viewWillAppear, optionArray became nil.
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.view.tintColor = [UIColor blackColor];
[self layoutButtons];
}
-(void)layoutButtons {
CGRect buttonRect = CGRectMake(START_POSTITION_X, START_POSTITION_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
int arrayPosition = 0;
for (NSString *buttonTitle in _optionArray) {
UIButton *button = [[UIButton alloc] initWithFrame:buttonRect];
[button setTitle:buttonTitle forState:UIControlStateNormal];
}
[self.view addSubview:button];
arrayPosition++;
}
}
I just found the solution.
Changed from weak to strong, and then everything worked again. @property (strong, nonatomic) NSArray *optionArray;
Not sure what changed iOS9 caused this behavior.