почему я продолжаю получать ожидаемую декларацию - PullRequest
0 голосов
/ 15 сентября 2018
@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {

    var textField = UITextField()

    let alert = UIAlertController(title: "Add New File", message:"", preferredStyle: .alert)


    let action = UIAlertAction(title: "Add Item", style: .default) { (action) in

        //what will happen after user clicks button
        print(textField.text)
    }
}

alert.addTextField {  (alertTextField) in //where the error begins help

alertTextField.placeholder = "Create New File"

textField = alertTextField



}
present(alert,animated: true,completion:nil)


}

Ответы [ 2 ]

0 голосов
/ 15 сентября 2018

Удалить лишние фигурные скобки (до alert.addTextField)

Ваш обновленный код:

@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {

    var textField = UITextField()
    let alert = UIAlertController(title: "Add New File", message:"", preferredStyle: .alert)

    let action = UIAlertAction(title: "Add Item", style: .default) { (action) in
        //what will happen after user clicks button
        print(textField.text)
    }

    alert.addTextField {  (alertTextField) in //where the error begins help
        alertTextField.placeholder = "Create New File"
        textField = alertTextField
    }
    present(alert,animated: true,completion:nil)
}
0 голосов
/ 15 сентября 2018

Похоже, вы запутались в скобках.Вы закрыли IBAction func после настройки action.

Обновленный код:

@IBAction func addButtonPressed(_ sender: UIBarButtonItem) {

    var textField = UITextField()

    let alert = UIAlertController(title: "Add New File", message:"", preferredStyle: .alert)


    let action = UIAlertAction(title: "Add Item", style: .default) { (action) in

        //what will happen after user clicks button
        print(textField.text)
    }

    alert.addTextField {  (alertTextField) in //where the error begins help
        alertTextField.placeholder = "Create New File"

        textField = alertTextField
    }
    present(alert,animated: true,completion:nil)
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...