UIButton在我的手机中没有响应,但模拟器

时间:2016-11-22 20:41:37

标签: ios iphone xcode uibutton

当我使用模拟器运行我的项目时,按钮响应并返回数据,但是当我使用我的iPhone时,我看到按钮的alpha变化,但它返回nil!

我正在使用HTTP请求并且该按钮处于查看状态。 它是注册按钮

enter image description here

enter image description here

修改 我的代码

@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,但在模拟器中它可以正常运行

0 个答案:

没有答案