【问题标题】:Unable to present UIAlertController within a UITableViewController in Swift无法在 Swift 中的 UITableViewController 中显示 UIAlertController
【发布时间】:2017-01-19 09:30:12
【问题描述】:

我有一个 UIAlertController,我想在 UITableViewController 中展示它。但是,当我运行代码时,出现以下错误:

警告:尝试在 谁的观点不在 窗口层次结构!

我的代码似乎反映了answer 中的建议。我做错了什么?

override func viewDidLoad() {
    super.viewDidLoad()

    // Check for force touch feature, and add force touch/previewing capability.
    if traitCollection.forceTouchCapability == .available {
        registerForPreviewing(with: self, sourceView: view)
    }
    else {
        // Create an alert to display to the user.
        alertController = UIAlertController(title: "3D Touch Not Available", message: "Unsupported device.", preferredStyle: .alert)
        self.present(alertController!, animated: false, completion: nil)
    }

【问题讨论】:

标签: ios swift uialertcontroller


【解决方案1】:

假设,在 viewDidLoad 中,您在窗口层次结构中仍然没有视图,如消息中所述。尝试将您的代码移至 viewDidAppear

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多