Ios 如果没有足够的时间,使用storyboardWithName传递数据将返回NULL
我试图找出为什么事情会以代码中描述的方式发生。Ios 如果没有足够的时间,使用storyboardWithName传递数据将返回NULL,ios,objective-c,cocoa-touch,parsing,storyboard,Ios,Objective C,Cocoa Touch,Parsing,Storyboard,我试图找出为什么事情会以代码中描述的方式发生。 我可以理解,如果aComb.someArray在instantialeviewcontrollerwhiteIdentifier期间尚未分配,它将返回NULL,但如果我设置计时器,数据将神奇地出现在那里。我想要一个解释和一个如何避免这种情况而不使用丑陋的计时器的想法 ViewControllerA: UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboar
我可以理解,如果
aComb.someArray
在instantialeviewcontrollerwhiteIdentifier
期间尚未分配,它将返回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];
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@",_someArray); //<-- this will return NULL
}
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: @selector(test)
userInfo: nil
repeats: NO];
}
-(void)test
{
NSLog(@"%@",_someArray); // <-- this will return Data
}
ViewControllerB:
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];
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@",_someArray); //<-- this will return NULL
}
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: @selector(test)
userInfo: nil
repeats: NO];
}
-(void)test
{
NSLog(@"%@",_someArray); // <-- this will return Data
}
-(void)viewDidLoad
{
[超级视图下载];
当调用aComb.view.frame=self.combinationscocontainer.bounds;
时,它会触发ViewControllerB的didLoad方法。但是当数组未分配时,它会返回Nil
。但是当计时器触发数组时,它会获取其值
要解决此问题,请在设置帧之前分配数组。我的意思是
aComb.someArray = _someArray;
aComb.view.frame = self.combinationsContainer.bounds;
在didLoad
和viewwillbeen
之间发生了一些事情。请尝试将NSLog
移动到viewwillbeen
,看看它是否具有所需的效果。或者甚至viewDidLoad
否,我仍然会得到NULL;InstanceViewController的标识符正在以某种方式调用viewDidLoad。您可以使用didLoad避免计时器的方法。您可以在viewDidLoad中保留断点,然后在实例化EviewController标识符之前检查。