cho*_*tik 8 cocoa-touch ios microsoft-band
我有一个具有以下层次结构的多视图应用程序:
splash - >导航控制器 - >表视图控制器 - >设置视图控制器
Splash是应用程序入口点,因此成为根视图控制器.当我尝试通过设置视图控制器上的操作向乐队添加磁贴时,我收到调试器警告:
application [1929:1000746]警告:尝试在<SplashViewController:0x15dd597b0>上显示<MSBAddTileDialogViewController_iOS:0x15f0575b0>,其视图不在窗口层次结构中!
这在调用后立即发生MSBClient.tileManager addTile:completionHandler:.调用永不返回,不会产生错误.
有关如何绕过这个的任何建议?
您将需要获取根视图控制器并从该视图控制器执行 Segue。这对于调试来说可能非常令人沮丧,但是这里有一些关于这个主题的答案。
这是我用来在应用程序收到推送通知时执行从根视图控制器到屏幕的一些代码。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboard" bundle:nil];
YourViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewcontrolleridentifier"];
UIViewController *top = [UIApplication sharedApplication].keyWindow.rootViewController;
[top presentViewController:viewController animated:YES completion: nil];
Run Code Online (Sandbox Code Playgroud)
下面是 swift 中的相同代码:
let storyboard = UIStoryboard.init(name: "YourStoryboard", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "viewcontrolleridentifier")
let top = UIApplication.shared.keyWindow?.rootViewController
top?.present(viewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
确保在故事板中设置视图控制器标识符。
编辑*如果您正在访问的视图控制器嵌入在导航控制器中,您将需要修改上面的代码,
目标C:
UIViewController *top = [self topMostController];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[top presentViewController:navigationController animated:YES completion: nil];
Run Code Online (Sandbox Code Playgroud)
迅速:
let top = UIApplication.shared.keyWindow?.rootViewController
let navigationController = UINavigationController.init(rootViewController: viewController)
top?.present(navigationController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)