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

问题出在传值到主界面后判断网页链接再跳转的时候 出现Attempt to present on whose view is not in the window hierarchy的错误,也就是传值回去的时候主视图还没打开又要打开浏览视图 然后就乱掉了 不知道要打开啥了。

尝试诸多方法之后找到以下方法:

在扫描结果之后 先跳转到主页,这个时候还没回传结果。
因为是跳过来的 所以用dismiss退回去

 self.dismissViewControllerAnimated(true, completion:nil)

然后,重写生命周期中的方法:viewDidDisappear 也就是在视图已经消失、被覆盖或是隐藏时再把值传递过去

    override func viewDidDisappear(animated: Bool) {
self.scanDelegate.didReturnScanResult(scanResultValue!);
}

这样就可以了。

swift一次 Attempt to present on whose view is not in the window hierarchy的解决方法的更多相关文章

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

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

  2. 错误: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 ...

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

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

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

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

  5. Swift - whose view is not in the window hierarchy 问题解决方法

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

  6. Warning: Attempt to present on whose view is not in模态跳转问题

    错误分析:            controller A present controller B ,前提是A的view要存在,如果不存在,就会报这个错.   解决方法:             将 ...

  7. 解决No 'Access-Control-Allow-Origin' header is present on the requested resource.跨域问题(后台(java)解决方法)

    附:前端常见跨域解决方案(全) 跨域错误 解决方法 在后台写一个过滤器来改写请求头 附上一个前端不知所以然的后台java代码: public class CorsFilter implements F ...

  8. Attempt to present <vc> on <vc> which is already presenting <vc>/(null)

    在给 tableViewCell 添加长按手势弹出一个 popViewController 的时候,遇到的这个变态问题: Warning: Attempt to present <UINavig ...

  9. Warning: Attempt to present * on * which is already presenting *

    Warning: Attempt to present (要被presented的控制器)  on (哪个控制器来presenting) which is already presenting (已经 ...

随机推荐

  1. 【machine learning通俗讲解code逐行注释】之线性回归实现

    现在机器学习算法在分类.回归.数据挖掘等问题上运用的十分广泛,对于初学者来说,可能一听到'算法'或其他的专属名词都感觉高深莫测,以致很多人望而却步,这让很多人在处理很多问题上失去了一个很有用的工具.机 ...

  2. css03层次选择器

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. 剑指offer--33.丑数

    本来用数组做标志位,但是测试数据有第1500个,859963392,惹不起哦 ------------------------------------------------------------- ...

  4. S2SH框架中的无刷新验证码功能实现

    暑假期间在实验室做使用S2SH框架的项目,其中登录和注册需要验证码,实现了一个没有实现刷新验证码功能的简单版本,代码如下: 1 package com.sem.action; 2 3 import j ...

  5. (二)Vue常用7个属性

    学习vue我们必须之到它的7个属性,8个 方法,以及7个指令.787原则 el属性 用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符. data属性 用来组织从view中抽象出 ...

  6. Linux 安全rm

    先将shell脚本放在某个全局路径下,如/usr/local/bin #!/bin/sh # safe rm # Don't remove the file, just move them to a ...

  7. Kafka源码深度解析-序列7 -Consumer -coordinator协议与heartbeat实现原理

    转自:http://blog.csdn.net/chunlongyu/article/details/52791874 单线程的consumer 在前面我们讲过,KafkaProducer是线程安全的 ...

  8. Weex 解析(二)—— NativeBridge

    (本篇幅主要讲解Weex 中iOS native与js交互实现) 大纲: weex 总框架预览 iOS NativeBridge总设计原理 一.weex 总框架预览 在写NativeBridge 总设 ...

  9. 文本溢出显示省略号,CSS未加载时a标签仍可用处理方法

    一.文本溢出打点 (1)单行文本 overflow: hidden; text-overflow:ellipsis; white-space: nowrap; (2)多行文本 overflow : h ...

  10. django配置静态文件

    django配置静态文件 参考文章链接:http://blog.csdn.net/hireboy/article/details/8806098