小编Nin*_*a13的帖子

如何在swift 3中使用addTarget方法

这是我的button对象

    let loginRegisterButton:UIButton = {
    let button = UIButton(type: .system)
    button.backgroundColor = UIColor(r: 50 , g: 80, b: 130)
    button.setTitle("Register", for: .normal)
    button.translatesAutoresizingMaskIntoConstraints = false
    button.setTitleColor(.white, for: .normal)
    button.addTarget(self, action:#selector(handleRegister), for: .touchUpInside)
    return button
}()
Run Code Online (Sandbox Code Playgroud)

这是我的功能

    func handleRegister(){

    FIRAuth.auth()?.createUser(withEmail: email, password: password,completion: { (user, error) in

        if error != nil
        { print("Error Occured")}

        else
        {print("Successfully Authenticated")}
    })        
}
Run Code Online (Sandbox Code Playgroud)

我收到编译错误,如果addTarget删除它成功编译

selector ios swift

54
推荐指数
5
解决办法
9万
查看次数

带花括号和圆括号的块如何工作?

let loginRegisterButton:UIButton = {
    let button = UIButton(type: .system)
    button.backgroundColor = .white
    button.setTitle("Register", for: .normal)
    button.translatesAutoresizingMaskIntoConstraints = false
    button.setTitleColor(.white, for: .normal)
    return button
}()
Run Code Online (Sandbox Code Playgroud)

是这个变量还是函数,它为什么会返回值?我们为什么称呼它?它不起作用parenthesis,为什么?

swift

9
推荐指数
1
解决办法
671
查看次数

标签 统计

swift ×2

ios ×1

selector ×1