我无法从应用程序委托中呈现ViewController

时间:2018-07-04 14:15:35

标签: ios objective-c

代码:

Appdelegate.h

- (void)goNativeStoryboardToTwilio;

Appdelegate.m

-(void)goNativeStoryboardToTwilio {

  DummyViewController *vc = [[UIStoryboard storyboardWithName:@"NativeStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"dummy"];
  [self.window.rootViewController presentViewController:vc animated:true completion:nil];
}

RoomInputToolbarView.m:

- (IBAction)twilioCall:(UIButton *)sender {
  AppDelegate *appdel=(AppDelegate *)[[UIApplication sharedApplication]delegate];
  [appdel goNativeStoryboardToTwilio];
}

RoomInputToolbarView.xib:

That call image is the twilioCall action

结果:

Warning: Attempt to present <DummyViewController: 0x1565f9910> on <UIViewController: 0x157831460> whose view is not in the window hierarchy!

我没有重定向到该页面。有人可以帮我解决这个问题。

更新

Appdelegate.m

-(void)goNativeStoryboardToTwilio {
  double delayInSeconds = 10.0;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    DummyViewController *vc = [[UIStoryboard storyboardWithName:@"NativeStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"dummy"];
    [self.window.rootViewController presentViewController:vc animated:true completion:nil];
  });
}

即使现在我也得到相同的结果。但是在该视图控制器中打印的所有日志都将被打印,只有屏幕没有改变。谁能给我建议解决方案?

1 个答案:

答案 0 :(得分:2)

问题是,您甚至在VC完全放置在窗口中之前就调用了present,因此您需要延迟它或将其推迟到ViewController的重写方法之内