首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UIAlertController不在不同入口点的层次结构中

UIAlertController不在不同入口点的层次结构中
EN

Stack Overflow用户
提问于 2019-03-05 06:40:50
回答 1查看 68关注 0票数 0

我有一个应用程序,人们可以用来请求服务。我有一个选项卡栏控制器,它使用第一个选项卡上的导航控制器,它有几个页面,用于不同的内容,如服务,位置和客户信息。它们都有UIAlertViews,当我把tabBarController作为应用程序的入口点时,一切都运行得很好。然后我决定添加一个不同的UIViewController,以便他们可以选择tabBarController或不同的tabBarController。如果这有意义的话,可以说是两个应用程序合二为一。当我把这个UIViewController作为应用程序的入口点时,除了最后一个之外,所有的UIAlertViews都可以工作。它显示“警告:尝试显示不在窗口层次结构中的视图!”以下是我的代码

代码语言:javascript
复制
@IBAction func send(_ sender: Any)
{

    name.resignFirstResponder()
    dismiss(animated: true, completion: nil)
    year.resignFirstResponder()
    dismiss(animated: true, completion: nil)
    make.resignFirstResponder()
    dismiss(animated: true, completion: nil)
    model.resignFirstResponder()
    dismiss(animated: true, completion: nil)
    color.resignFirstResponder()
    dismiss(animated: true, completion: nil)
    note.resignFirstResponder()
    dismiss(animated: true, completion: nil)

    let alertController = UIAlertController(title: "You will now email your service request. The recipient email adress and message will be preset, all you have to do is hit send.", message: "Message and data rates may apply.", preferredStyle: .alert)
    let okAction = UIAlertAction(title: "ok", style: UIAlertActionStyle.default)
    {
        UIAlertAction in
        let mailcomposedViewController = self.configureMailController()
        if MFMailComposeViewController.canSendMail()
        {
            self.present(mailcomposedViewController, animated: true, completion: nil)
        }
        else
        {
            self.showMailError()
        }
    }

    alertController.addAction(okAction)


    self.present(alertController, animated: true, completion: nil)
}

有人能告诉我为什么Alert在一个入口点上工作,而在另一个入口点上不工作吗?

当我把应用程序的入口点放在标签栏控制器(上图)上时,一切都很好。但是当我把入口点作为UIView (底图)时,只有最后一部分不起作用。

EN

回答 1

Stack Overflow用户

发布于 2019-03-05 08:45:54

问题是这一行:

代码语言:javascript
复制
dismiss(animated: true, completion: nil)

你说了一遍又一遍(没有理由)。您(self)是一个呈现的视图控制器,所以您现在忽略了自己。因此,当您说self.present时,您不再处于视图层次结构中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54992714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档