problem: When you want to initialize the page, use the Self.presentviewcontroller method to pop up a warning box uialertcontroller. But after the line reported the following alarm, and the alarm box can not come out.
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! |
Workaround: The original calling code is written in the Viewdidload method, which indicates that the view is loaded. We should put the method call into Viewdidapper, which is called when the view of the Uiviewcontroller object has been added to the window.
123456789101112131415161718192021222324 |
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 isn't in the window hierarchy problem solving method