コードで説明されているように物事が起こっている理由を理解しようとしています。aComb.someArray
時間内にまだ割り当てられていない場合はinstantiateViewControllerWithIdentifier
NULLを返しますが、タイマーを設定するとデータが魔法のようにそこに表示されることを理解できます。いタイマーを使用せずにこれを回避する方法の説明とアイデアが欲しいです。
ViewControllerA:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewControllerB *aComb = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerBID"];
aComb.view.frame = self.combinationsContainer.bounds;
aComb.someArray = _someArray;
[self.combinationsContainer addSubview:aComb.view];
[self addChildViewController:aComb];
[aComb didMoveToParentViewController:self];
ViewControllerB:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@",_someArray); //<-- this will return NULL
}
タイマー付きのViewControllerB:
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: @selector(test)
userInfo: nil
repeats: NO];
}
-(void)test
{
NSLog(@"%@",_someArray); // <-- this will return Data
}