PerformSegueWithIdentifier

时间:2015-09-19 11:42:30

标签: ios swift swift2

我正在使用警报执行Segue到另一个视图。

                let defaultAction = UIAlertAction(title: "Proceed", style: .Default, handler: { (UIAlertAction) -> Void in

                    performSegueWithIdentifier("proceed", sender: self)

                })

我无法弄清楚为什么会收到错误:

Extra argument 'sender' in call

发件人应该只是自己,对吗? 这个错误让我疯狂了好几个小时,我无法弄清楚出了什么问题! 任何帮助表示赞赏!谢谢!

3 个答案:

答案 0 :(得分:0)

试试这个

let alert = UIAlertView()
        alert.title = "Download Complete"
        alert.message = "he list of user IDs has been downloaded. Proceed to know who viewed your profile."
        alert.addButtonWithTitle("ok")
        alert.show()

        var okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) {
            UIAlertAction in
            NSLog("OK Pressed")
            performSegueWithIdentifier("proceed", sender: nil)
        }
        alertController.addAction(okAction)

答案 1 :(得分:0)

所以这是我的完整代码:

let alertController = UIAlertController(title: "Download Complete", message: "The list of user IDs has been downloaded. Proceed to know who viewed your profile.", preferredStyle: .Alert)
                let defaultAction = UIAlertAction(title: "Proceed", style: .Default, handler: { (UIAlertAction) -> Void in

                    performSegueWithIdentifier("proceed", sender: nil)

                })


override func viewDidLoad() {
    super.viewDidLoad()






                self.alertController.addAction(self.defaultAction)
                self.presentViewController(self.alertController, animated: true, completion: nil)


           }

答案 2 :(得分:0)

试试这段代码:

override func viewDidLoad() {
   super.viewDidLoad()
    self.showAlert() //Calling function
}

func showAlert()
{
  let alertController = UIAlertController(title: "Download Complete", message: "The list of user IDs has been downloaded. Proceed to know who viewed your profile.", preferredStyle: .Alert)
  let defaultAction = UIAlertAction(title: "Proceed", style: .Default, handler: { (UIAlertAction) -> Void in
         self.performSegueWithIdentifier("proceed", sender: self)
  })
 alertController.addAction(defaultAction)
 self.presentViewController(alertController, animated: true, completion:nil)
}