在自定义构建的 UIViewControllers 值之间传递数据在 iOS 9 中变为 nil 在 iOS8 中工作

Passing Data Between Custom Built UIViewControllers Value Became nil in iOS 9 working in iOS8

我创建了一个自定义 UIViewController。

@property (weak, nonatomic) NSArray *optionArray;

-(VCSelectionViewController*) getPopoverViewControllerForTextField:(UITextField*)textField {

UIViewController *buttonPopover = [[UIViewController alloc] init];
buttonPopover.optionArray = [OptionArray getLOCQualityArray]

但是 iOS9 的 viewWillAppear 中的 optionArray 值变为 nil。它在 iOS8 工作。我在这上面花了好几个小时,但没有运气。

这是我调用上面列出的 getPopoverViewControllerForTextField 方法的地方。

-(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];
}

执行上面的代码后,我仍然可以看到 optionArray 值。 optionArray 仍然存在于

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

但是当它开始执行viewWillAppear时,optionArray变成了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++;
     }
}

我刚刚找到了解决方案。

由弱变强,然后一切正常。 @属性 (strong, nonatomic) NSArray *optionArray;

不确定是什么改变了 iOS9 导致了这种行为。