博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift - whose view is not in the window hierarchy 问题解决方法
阅读量:4483 次
发布时间:2019-06-08

本文共 1343 字,大约阅读时间需要 4 分钟。

问题现象:想在页面初始化的时候,使用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.
    
}
}

转载于:https://www.cnblogs.com/Free-Thinker/p/4838386.html

你可能感兴趣的文章
MySQL服务器的安装和配置,MySQL Workbench 8.0.12安装,MySQL的基本使用
查看>>
扑克序列
查看>>
java笔记--适配器模式的运用
查看>>
C#与数据结构--图的遍历
查看>>
ispy 编译笔记
查看>>
bzoj1067——SCOI2007降雨量(线段树,细节题)
查看>>
day 1
查看>>
洛谷P1282 多米诺骨牌【线性dp】
查看>>
数据类型的提升(promotion)
查看>>
Thead是不能返回值的,但是作为更高级的Task当然要弥补一下这个功能。
查看>>
Python中的生成器与yield
查看>>
JQuery 的Bind()事件
查看>>
Maven 常用配置
查看>>
Objects源码解析
查看>>
video
查看>>
栈的c语言顺序实现(动态申请空间)
查看>>
【转】 Pro Android学习笔记(六七):HTTP服务(1):HTTP GET
查看>>
获取子iframe框架的元素
查看>>
WordCount bug修复录
查看>>
承载进程 (vshost.exe)
查看>>