问题现象:想在页面初始化的时候,使用self.presentViewController方法弹出个告警提示框UIAlertController。但行后报了个如下告警,同时告警框也出不来。

1
2015-03-10 09:55:34.197 Test[1140:29622] Warning: Attempt to present <UIAlertController: 0x7c95ca20> on <Test.ViewController: 0x7a6afc60> whose view is not in the window hierarchy!

解决办法:原来的调用代码是写在viewDidLoad方法中,这个表示视图加载完毕。我们应该把方法调用放到viewDidApper中,这个是UIViewController对象的视图已经加入到窗口时调用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import UIKit
 
class ViewController: UIViewController ,UIActionSheetDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
     
    override func viewDidAppear(animated: Bool){
        super.viewDidAppear(animated)
         
        var alertController = UIAlertController(title: "系统提示",
            message: "您确定要离开hangge.com吗?", preferredStyle: UIAlertControllerStyle.Alert)
        var cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)
        var okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default, handler: nil)
        alertController.addAction(cancelAction)
        alertController.addAction(okAction)
        self.presentViewController(alertController, animated: true, completion: nil)
    }
       
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Swift - whose view is not in the window hierarchy 问题解决方法的更多相关文章

  1. swift一次 Attempt to present on whose view is not in the window hierarchy的解决方法

    做的是二维码扫描,扫描后识别为URL的话就跳转到webview 加载网页,用的是代理传值的方式.扫描到了 值传递到主页 扫描窗体退出,检测值是否是http://开头 是网页就跳转. 问题出在传值到主界 ...

  2. IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

    在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" ...

  3. whose view is not in the window hierarchy

    参考:http://www.jianshu.com/p/9e90cb866fdf 在做界面跳转的时候,我们经常会用到这两个函数 func dismissViewControllerAnimated(f ...

  4. Warning: Attempt to present on whose view is not in the window hierarchy!

    当我想从一个VC跳转到另一个VC的时候,一般会用 - (void)presentViewController:(UIViewController *)viewControllerToPresent a ...

  5. 错误:Warning: Attempt to present <UIAlertController: 0x7fd192806e20> on <ViewController: 0x7fd1928048d0> whose view is not in the window hierarchy!

    系统:mac OS  10.12 (16A323) Xcod:8.3.3 错误:Warning: Attempt to present <UIAlertController: 0x7fd1928 ...

  6. iOS开发出错whose view is not in the window hierarchy!的解决

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 一个简单的单窗口App在运行时出现错误: 2016-04-07 ...

  7. Attempt to present <TestViewController2: 0x7fd7f8d10f30> on <ViewController: 0x7fd7f8c054c0> whose view is not in the window hierarchy!

    当 storyboard里面的 按钮 即连接了 类文件里面的点击方法  又  连接了   storyboard里 另一个  控制器的  modal 就会出现类似Attempt to present & ...

  8. Warning: Attempt to present A on B whose view is not in the window hierarchy!

    昨天写豆瓣发广播Demo的时候,为了写Demo的简单,就使用了Storyboard,结果执行视图跳转时遇到了这个问题: Warning: Attempt to present <UINaviga ...

  9. iOS whose view is not in the window hierarchy!

    解决方法: viewController只Load完毕,没有Appear,此时应该将语句转移到ViewDidAppear方法中

随机推荐

  1. CCIE路由实验(3) -- BGP高级部分

    当一个AS包含多个IBGP对等体时,路由反射器非常有用.因为IBGP客户只需要和路由反射器建立邻居关系,从而降低了IBGP的连接数量.路由反射器和它的客户合称为一个簇.路由反射是克服IBGP水平分割的 ...

  2. 基于visual Studio2013解决C语言竞赛题之0514单词统计

     题目 解决代码及点评 /************************************************************************/ /* 14. 有一行字 ...

  3. Vmware虚拟机下三种网络模式配置

    VMware虚拟机有三种网络模式,分别是Bridged(桥接模式).NAT(网络地址转换模式).Host-only(主机模式). VMware workstation安装好之后会多出两个网络连接,分别 ...

  4. jfinal集成spring cxf做webservice服务

    链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...

  5. 黑龙江省第七届大学生程序设计竞赛-Heap

    描述 A heap is a full binary tree; for each node, its key is greater than its two sub-node’s key. Two ...

  6. set global read_only=0; 关闭只读,可以读写 set global read_only=1; 开始只读模式

    mysql> set global read_only=0; Query OK, 0 rows affected (0.00 sec) mysql> show variables like ...

  7. 深入浅出单实例Singleton设计模式

    深入浅出单实例Singleton设计模式 陈皓 单实例Singleton设计模式可能是被讨论和使用的最广泛的一个设计模式了,这可能也是面试中问得最多的一个设计模式了.这个设计模式主要目的是想在整个系统 ...

  8. 基于visual Studio2013解决C语言竞赛题之0704字符串长度

     题目

  9. 面试题之——抽象类(abstract class)与接口(interface)的区别

    抽象类可以有构造方法,接口中不能有构造方法.(虽然抽象类有构造方法,但它也不能被实例化) 抽象类中可以有普通成员变量,接口中没有普通成员变量. 抽象类和接口中都可以包含静态成员变量.抽象类中的静态成员 ...

  10. 关于运行robotium提示连接不上jar问题

    robotium运行测试helloworld报错: java.lang.NoClassDefFoundError: com.jayway.android.robotium.solo.Solo at c ...