Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改静态func闭包的UIButton属性_Ios_Swift_Iphone - Fatal编程技术网

Ios 更改静态func闭包的UIButton属性

Ios 更改静态func闭包的UIButton属性,ios,swift,iphone,Ios,Swift,Iphone,我有静态API函数,它是void并调用外部API,现在我想检查响应,当它是nil时,我想禁用按钮并更改其颜色。 但在Alamofire中,即使使用self,我也无法访问按钮属性 @IBOutlet weak var AudioButton: UIButton! override func viewDidLoad() { super.viewDidLoad() // self.AudioButton.tintColor=UIColor.gray work here

我有静态API函数,它是void并调用外部API,现在我想检查响应,当它是nil时,我想禁用按钮并更改其颜色。 但在Alamofire中,即使使用self,我也无法访问按钮属性

@IBOutlet weak var AudioButton: UIButton!

override func viewDidLoad() {
        super.viewDidLoad()
  // self.AudioButton.tintColor=UIColor.gray work here 
       if(gameData?.WordId != nil){

    APIClient.getWordAudio(id: gameData!.WordId)
                .execute(onSuccess: { response in
                    DatabaseManager.shared.saveWordAudios([response])//
                  let audioData = NSData(base64Encoded: response.content!, options: .ignoreUnknownCharacters)
                    // here I want to check for nil and then disable the button
 if(response.content==nil){
// this two line dosen't work inside this closure
                     self.AudioButton.tintColor=UIColor.gray                    
                    self.AudioButton.isEnabled=false;
                    }

              }, onFailure: { error in
                  print("[WordViewController] \(error)")

              }
                  )


        }

}

请出示音频按钮的声明。我认为您正在访问类
AudioButton
,而不是它的对象

let audioButton: AudioButton?
然后从闭包内部访问对象

if(response.content==nil){
    self.audioButton.tintColor=UIColor.gray                    
    self.audioButton.isEnabled=false;
}

请出示音频按钮的声明。我认为您正在访问类
AudioButton
,而不是它的对象

let audioButton: AudioButton?
然后从闭包内部访问对象

if(response.content==nil){
    self.audioButton.tintColor=UIColor.gray                    
    self.audioButton.isEnabled=false;
}

将AudioButton设置为强变量,我认为它会工作


@IBOutlet var AudioButton:UIButton

将AudioButton设置为强变量,我认为它会起作用


@IBOutlet var AudioButton:UIButton

刚刚测试了此功能,工作正常:

@IBOutlet弱var AudioButton:UIButton!
重写func viewDidLoad(){
super.viewDidLoad()
self.AudioButton.tintColor=UIColor.red
Alamofire.request(“https://api.androidhive.info/contacts/)。responseData{(responseData)->在
if(responseData.data!=nil){
self.AudioButton.tintColor=UIColor.gray
self.AudioButton.isEnabled=false
}
}
}
输出:


我用Alamofire 4.0.0和5.0.0-beta.5进行了测试,刚刚测试了这个,工作正常:

@IBOutlet弱var AudioButton:UIButton!
重写func viewDidLoad(){
super.viewDidLoad()
self.AudioButton.tintColor=UIColor.red
Alamofire.request(“https://api.androidhive.info/contacts/)。responseData{(responseData)->在
if(responseData.data!=nil){
self.AudioButton.tintColor=UIColor.gray
self.AudioButton.isEnabled=false
}
}
}
输出:


我用Alamofire 4.0.0和5.0.0-beta.5进行了测试,请出示AudioButton声明,这是一个简单的插座@IBOutlet弱var AudioButton:UIButton!是的,值现在不重要了,我尝试了,但运气不好。检查括号。@PayamKhaninejad尝试将tintColor更改为BackgroundColor。(我刚刚在示例项目上试用过,它不适用于tintColor,但适用于backgroundColor)也可以正常工作。请显示AudioButton声明它是一个简单的插座@IBOutlet弱var AudioButton:UIButton!是的,值现在不重要了,我尝试了,但运气不好。检查括号。@PayamKhaninejad尝试将tintColor更改为BackgroundColor。(我刚刚在示例项目上试用过,它不适用于tintColor,但适用于backgroundColor)也可以正常工作。否,请参阅关于该问题的按钮声明。未声明类型“AudioButton”的使用否请参见有关问题的按钮声明。未声明类型“AudioButton”的使用