Передача нескольких параметров в UIAlertAction в Swift - PullRequest
0 голосов
/ 25 мая 2018

Я пытался найти способ передать несколько параметров в UIAlertAction.Ниже мой код.Я хочу передать строку «source» действию joinSelected оповещения.

Я получаю сообщение об ошибке, подобное этому:

Невозможно преобразовать значение типа '()' вожидаемый тип аргумента '((UIAlertAction) ->

fileprivate func showBetaAlert(source: String)  {
        let betaAlert =  UIAlertController.betaProgramAlert()
        let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: joinSelected(alert: <#UIAlertAction#>, source: source))
        let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: cancelSelected)

        betaAlert.addAction(cancelAction)
        betaAlert.addAction(joinAction)

        present(betaAlert, animated: true, completion: nil)

    }

fileprivate func joinSelected(alert: UIAlertAction, source: String) {
        let betaAlert = UIAlertController.signUpAlert()
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: dismissEmailAction)
        let submitAction = UIAlertAction(title: "Submit", style: .default , handler: { [weak self] _ in
            guard let stelf = self else { return }
            let email = betaAlert.textFields![0] as UITextField
            stelf.submitAction(email: email.text!)
        })

        betaAlert.addAction(cancelAction)
        betaAlert.addAction(submitAction)

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

1 Ответ

0 голосов
/ 25 мая 2018

Замените эту строку:

let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: joinSelected(alert: <#UIAlertAction#>, source: source))

на:

let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: { [weak self] _ in
    joinSelected(source: source)
})

и обновите joinSelected до:

fileprivate func joinSelected(source: String) {
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...