objective c - iOS: change view from viewDidAppear -
i'm playing around view life cycles & having trouble changing view load of different view.
in viewcontroller.h have:
-(void)viewdidappear:(bool)animated{ uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; viewcontroller2 *viewcontroller = (viewcontroller2 *)[storyboard instantiateviewcontrollerwithidentifier:@"viewcontroller2"]; [self presentviewcontroller:viewcontroller animated:yes completion:nil]; }
however causes view between viewcontroller, , viewcontroller2 appearing animation (in loop).
i used code in viewdidload
neither of view's loaded (from reading cannot change view until viewwillappear)
update: when using code in viewwillappear
, whose view not in window hierarchy
error thrown.
how 1 change view view setup stage?
update using above code, inside & out of gcd, in viewdidload
, viewwillappear
& viewdidappear
either results in infinite loop of animated showing of viewcontroller2, or crash on 2nd attempt of segue (result loop).
edited:
i'm not sure you're trying do, assuming wanting first viewcontroller appear , second viewcontroller animate on top of first one, should able accomplish using several options:
first wrap calls in dispatch_async call:
dispatch_async(dispatch_get_main_queue(), ^{ uistoryboard *storyboard = [uistoryboard storyboardwithname:@"main" bundle:nil]; viewcontroller2 *viewcontroller = (viewcontroller2 *)[storyboard instantiateviewcontrollerwithidentifier:@"viewcontroller2"]; [self presentviewcontroller:viewcontroller animated:yes completion:nil]; });
or use show modally segue:
- (void)viewdidload { [super viewdidload]; dispatch_async(dispatch_get_main_queue(), ^{ [self performseguewithidentifier:@"mymodalsegue" sender:self]; }); }
or use navigation controller , use standard show segue (formally push). 1 doesn't require dispatch_async:
- (void)viewdidload { [super viewdidload]; [self performseguewithidentifier:@"myshowsegue" sender:self]; }
i've posted working examples of 3 on: github
Comments
Post a Comment