gpt4 book ai didi

swift - 使用 Swift 2.0 显示没有任何 UIButton 的 UIAlertController

转载 作者:行者123 更新时间:2023-11-30 14:00:56 27 4
gpt4 key购买 nike

我想答案很简单,但我已经尝试解决这个问题好几天了,但找不到解决方案。这是一个 UIViewController 经过某些检查并且不使用任何按钮,显示 UIAlertController。始终出现警告:尝试呈现不在窗口层次结构中的 View !

import UIKit

ViewController 类:UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
noData()
}

func noData(){
let alertController = UIAlertController(title: "Message", message: "There area no data in the file" , preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
}

}

最佳答案

您只需在 viewDidAppear 中调用 noData() 方法,而不是 viewDidLoad 即可。

override func viewDidAppear(animated: Bool) {
noData()
}

关于swift - 使用 Swift 2.0 显示没有任何 UIButton 的 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33003526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com