当我使用模拟器运行我的项目时,按钮响应并返回数据,但是当我使用我的iPhone时,我看到按钮的alpha变化,但它返回nil!
我正在使用HTTP请求并且该按钮处于查看状态。 它是注册按钮
修改 我的代码
@IBOutlet weak var signup: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
signup.alpha = 1;
}
func loginButton(_ enabled: Bool) -> () {
func enable(){
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.signup.backgroundColor = UIColor.colorWithHex("#33CC00", alpha: 1)
}, completion: nil)
signup.isEnabled = true
}
func disable(){
signup.isEnabled = false
UIView.animate(withDuration: 0.3, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations: {
self.signup.backgroundColor = UIColor.colorWithHex("#333333",alpha :1)
}, completion: nil)
}
return enabled ? enable() : disable()
}
@IBAction func signup(_ sender: UIButton) {
let urlstr = "http://localhost:8000/api/auth/signup"
let url = URL(string: urlstr)
let param = ["email": email.text, "password":password.text,"password_confirmation":confirm_password.text,"name":name.text]
request( url!, method: .post, parameters: param , encoding: JSONEncoding.default )
.responseJSON { response in
print(response.result.value)
if let value: AnyObject = response.result.value as AnyObject? {
//Handle the results as JSON
let usertoken = JSON(value)
print(usertoken)
if let token = usertoken["token"].string {
} else {
print("error")
}
}
}
}
当我在我的iPhone中运行时,它只打印nil,但在模拟器中它可以正常运行