【问题标题】:One UIAlertController function with multiple actions - is this possible?一个具有多个操作的 UIAlertController 函数 - 这可能吗?
【发布时间】:2015-06-09 21:03:03
【问题描述】:

以下代码是我编写的用于处理“返回”按钮和“注销”按钮的函数。当用户点击“取消”时,他将停留在当前视图上,当他点击“确定”时,他将被带到上一个视图或登录屏幕,具体取决于他点击的按钮。我可以用一个功能做到这一点,还是每个按钮都需要一个功能?我更喜欢一个可以创建全局函数并在所有三个视图中使用的函数。

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

我可以使用 performSegueWithIdentifier 然后使用带有 segue 标识符的 var 吗?那会是什么样子?我的意思是,在performSegueWithIdentifier 之后是否需要添加参数?

【问题讨论】:

    标签: ios swift segue uialertcontroller


    【解决方案1】:

    您只需指定一个不同的标识符,具体取决于您要展开到哪个视图控制器。

    您的 AlertController 将指定正确的标识符,具体取决于用户是否已注销(展开以登录)或没有(展开到上一个视图)。

    如果您需要传递其他信息,可以在 prepareForSegue 中进行设置。

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多