0

我创建了一个自定义 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++;
     }
}
4

1 回答 1

1

我刚刚找到了解决方案。

从弱变强,然后一切都恢复了。@property(强,非原子) NSArray *optionArray;

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

于 2015-09-24T21:37:15.310 回答