Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当alertviewcontroller打开时显示新VC_Ios_Swift_Uiviewcontroller_Swift3 - Fatal编程技术网

Ios 当alertviewcontroller打开时显示新VC

Ios 当alertviewcontroller打开时显示新VC,ios,swift,uiviewcontroller,swift3,Ios,Swift,Uiviewcontroller,Swift3,我想显示一个新的ViewController,但在显示AlertController时它不起作用。我不想使用现有的segue,只想在swift中使用。有人能帮我吗? 这只是一个简单的例子,在我的应用程序中,我使用一个自定义的AlertController来显示加载程序。所以,我不想在点击警报按钮后被重定向 提前谢谢 Ps:对不起,我的英语不好 @IBAction func testButtonClick(_ sender: AnyObject) { let alert = UIAlert

我想显示一个新的ViewController,但在显示AlertController时它不起作用。我不想使用现有的segue,只想在swift中使用。有人能帮我吗? 这只是一个简单的例子,在我的应用程序中,我使用一个自定义的AlertController来显示加载程序。所以,我不想在点击警报按钮后被重定向

提前谢谢

Ps:对不起,我的英语不好

@IBAction func testButtonClick(_ sender: AnyObject) {
    let alert = UIAlertController(title: nil, message: "test", preferredStyle: UIAlertControllerStyle.alert)
    self.present(alert, animated: true, completion: nil)
    logout()
}

func logout() {
    let storyboardName = "Authentication"
    let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
    if let newVC = storyboard.instantiateInitialViewController() {
        newVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen
        self.present(newVC, animated: true)
    } else {
        print("Unable to instantiate VC from \(storyboardName) storyboard")
    }
}

其中一个选项是,您可以在实例级别保持var中的警报,以便作为转换的先决条件,它首先关闭警报

var alert: UIAlertController?
在TestButton中单击:

alert = UIAlertController(title: nil, message: "test", preferredStyle: UIAlertControllerStyle.alert)
let completion = { self.alert = nil }
self.present(alert, animated: true, completion: completion)
注销时:

let completion = { self.alert = nil }
alert?.dismissViewController(animated: true, completion: completion)

注意:您还可以使您的生活变得轻松,并使用segues和prepareForSegue…

其中一个选项是,您可以将var中的警报保持在实例级别,以便作为过渡的先决条件,它首先将其关闭

var alert: UIAlertController?
在TestButton中单击:

alert = UIAlertController(title: nil, message: "test", preferredStyle: UIAlertControllerStyle.alert)
let completion = { self.alert = nil }
self.present(alert, animated: true, completion: completion)
注销时:

let completion = { self.alert = nil }
alert?.dismissViewController(animated: true, completion: completion)

注意:你也可以让你的生活变得轻松,使用segues和prepareForSegue…

你可以这样使用

let alert = UIAlertController(title: nil, message: "test", preferredStyle: UIAlertControllerStyle.alert)
        self.present(alert, animated: true, completion: nil)

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let newVC = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController


        newVC?.modalPresentationStyle = UIModalPresentationStyle.fullScreen

        presentedViewController?.present(newVC!, animated: true)

你可以用这种方式

let alert = UIAlertController(title: nil, message: "test", preferredStyle: UIAlertControllerStyle.alert)
        self.present(alert, animated: true, completion: nil)

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let newVC = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController


        newVC?.modalPresentationStyle = UIModalPresentationStyle.fullScreen

        presentedViewController?.present(newVC!, animated: true)

谢谢你的回答。但我的问题是,我在其他类中使用这个方法注销。事实上,我想在http请求出现错误时断开用户的连接。所以我想做一些全球性的事情。当出现错误时,将自动调用此方法注销。我可以在任何viewcontroller上发出请求。所以,如果我想使用segues,我必须为每个故事板创建一个,不是吗?我想,这是放松segues可以帮助的。此外,也许你的应用程序使用了一个或多个路由器进行分段,这可以集中化逻辑。总的来说,在我看来,这种方法仍然有效。调用注销将关闭AlertViewController(如果它存在),如果它为零则不关闭。是的,它可以工作,但我必须将AlertViewController和我的vc的引用发送到类请求。所以我更喜欢Vinod Kumar的解决方案。但是谢谢你的帮助谢谢你的回答。但我的问题是,我在其他类中使用这个方法注销。事实上,我想在http请求出现错误时断开用户的连接。所以我想做一些全球性的事情。当出现错误时,将自动调用此方法注销。我可以在任何viewcontroller上发出请求。所以,如果我想使用segues,我必须为每个故事板创建一个,不是吗?我想,这是放松segues可以帮助的。此外,也许你的应用程序使用了一个或多个路由器进行分段,这可以集中化逻辑。总的来说,在我看来,这种方法仍然有效。调用注销将关闭AlertViewController(如果它存在),如果它为零则不关闭。是的,它可以工作,但我必须将AlertViewController和我的vc的引用发送到类请求。所以我更喜欢Vinod Kumar的解决方案。但是谢谢你的帮助