モーダルでViewControllerを遷移中、"Attempt to present on ..whose view is not in the window hierarchy!"のエラーが出て新しいViewを表示することができません。
今の実装手順はこちらです。
1.aViewControllerからbViewControllerにモーダルで遷移 2.AppDelegateのBecomeActiveを用い、bViewControllerでアクティブ状態に戻った後一番上の画面(この場合bViewController)に新しいViewを貼りつける (Viewを貼り付けるメソッドは"addView"で、名前も中身も同じものを各ViewControllerに書いています)
通知の実行対象をselfとするとselfがaViewControllerになってしまい、先ほどのエラーが出てしまいます。
同様にaViewControllerからcViewControllerに移った場合も、selfがaViewControllerになってしまいViewを貼り付ける事ができません。
(aViewControllerにいる時だけはアクティブ状態になると正常にViewを貼り付ける事ができます。)
その時一番上に貼ってあるViewControllerにViewを貼り付けたいのですが、どうしたら良いのでしょうか?
よろしくお願い致します。
AppDelegate.m
objective
1- (void)applicationDidBecomeActive:(UIApplication *)application 2{ 3 // 通知を作成 4 NSNotification *n = [NSNotification notificationWithName:@"Tuchi" object:self]; 5 6} 7
aViewController.m(bViewcontroller、cViewControllerも同様の内容です)
objective
1- (void)viewDidLoad{ 2. 3. 4. 5//アクティブ状態になったらaddViewを実行 6NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 7 [nc addObserver:self selector:@selector(addView) name:@"Tuchi" object:self]; 8 9} 10 11-(void)moveToB{ 12 bViewController *secondViewController = [[bViewController alloc] initWithNibName: nil bundle: nil]; 13 [self presentViewController:secondViewController animated:YES completion:nil]; 14} 15 16//Viewを貼り付ける 17- (void)addView{ 18 puv = [[UIView alloc]init]; 19 puv.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height); 20 puv.backgroundColor = [UIColor redColor]; 21 [self.view addSubview:puv]; 22}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。