调用中的额外参数“动画” - 错误

时间:2015-01-03 01:01:54

标签: ios swift

我试图获取弹出警报以将数据添加到数组中。简单吧?我以前做过它并且它完美地工作,但由于某种原因今天没有。这是我的代码。

@IBAction func addingCat(sender: UIButton) {


    //Creates the alert controller
    var alert = UIAlertController(title: "New Note Category", message: "Please enter the new Note category you wish to create.", preferredStyle: .Alert)

    //Adds the two text fields
    alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
        textField.placeholder = "Title"
        var myColor : UIColor = UIColor( red: 128, green: 0, blue:0, alpha: 1.0 )
        textField.layer.borderColor = myColor.CGColor
    })

    //Saves and prints the values from both text boxes when 'Save' is clicked
    alert.addAction(UIAlertAction(title: "Save", style: .Default, handler: { (action) -> Void in
        let textField = alert.textFields![0] as UITextField
        var titlePrac:String! = "\(textField.text)"

        if titlePrac.isEmpty {
            titlePrac = "New Category"
        }

    }))

    //Presents the alert
    UIAlertController.presentViewController(alert, animated: true, completion: nil) //Extra argument 'animated' in call
    UIApplication.sharedApplication().statusBarStyle = .LightContent

    var newTitle = "        "
    newTitle += "titlePrac"

    sideBarTableViewController.tableData.append(newTitle)
    sideBarTableViewController.tableView.reloadData()
    println("Worked")
    println(sideBarTableViewController.tableData)

}

错误发生在我的“提供警报”下的第一行。部分。它给出了错误:

Extra argument "animated" in call

我不知道为什么会这样。

1 个答案:

答案 0 :(得分:2)

您需要使用当前的ViewController显示警报。您需要更改以下代码:

UIAlertController.presentViewController(alert, animated: true, completion: nil)

为:

self.presentViewController(alert, animated: true, completion: nil)

同样UIAlertController没有任何名为presentViewController:的类方法。