dismissViewControllerAnimated为什么不起作用

「已注销」 2015-03-22 04:45:30
我的rootViewController是和xib对应的登录的LoginViewController,登录成功后,我想让这个ViewController关闭,然后弹出故事面板,但是调用dismissViewControllerAnimated后,LoginViewController没有消失,更没有弹出故事面板,请问哪里出错了呢?

代码如下:

self.dismissViewControllerAnimated(true, completion:
{
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil);
let window = UIWindow(frame: UIScreen.mainScreen().bounds);
window.rootViewController = mainStoryboard.instantiateInitialViewController() as? UIViewController;
});
...全文
745 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ReyZhang 2015-03-22
  • 打赏
  • 举报
回复
UIWindow是视图的载体,这个UIWindow是在AppDeleaget中定义的UIWindow 。你这里之所以没有效果的原因是,你自己创建的UIWindow。所以如果要起作用,你需要访问AppDelegate 中的UIWindow对象。你可以尝试通过通知的方式改变self.window?.rootViewController 的指向,如在AppDelegate中有showMain函数
func showMain() {
        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil);
       self.window?.rootViewController = mainStoryboard.instantiateInitialViewController() as? UIViewController;
}

1,420

社区成员

发帖
与我相关
我的任务
社区描述
Swift,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C共同运行于MAC OS和iOS平台,用于搭建基于苹果平台的应用程序。
swift 技术论坛(原bbs)
社区管理员
  • Swift
  • 网罗开发
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧