swift - UIAlertController 将用户带回到第一个 ViewController

swift - UIAlertController takes the user back to the first ViewController

我在我的应用程序中使用了 UIAlertController,只要用户单击“确定”,它就会将用户带回到第一个 viewcontroller。

var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()

func displayAlert(title:String, error: String){
    var alert = UIAlertController(title: title, message: error, preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { action in
        self.dismissViewControllerAnimated(true, completion: nil)
    }))
    self.presentViewController(alert, animated: true, completion: nil)
}

我使用上面的功能在 viewcontroller 上的任何时候显示警报。

这是怎么回事?我怎样才能让用户保持在当前 viewcontroller?

在您的操作中,您正在调用 self.dismissViewController - 在这种情况下,"self" 是当前视图控制器,而不是您的警报视图,因此您实际上是在请求删除当前视图控制器。