Swift-whose view isn't in the window hierarchy problem solving method

Source: Internet
Author: User

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 UIKitclass 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.