Modifying UIButton's alpha property from another class

前端 未结 3 1305
轮回少年
轮回少年 2021-01-15 15:21

I\'m trying to change the alpha of an UIButton from another class. The function that is called in set the alpha property of my UIButto

3条回答
  •  感情败类
    2021-01-15 16:08

    In your code, an instance of ViewController is alloced and inited, and the method setAlphaToButton is called on it. Then the view controller is released because you have no object retaining it. That's why you don't see any effect; the ViewController instance you call the method on never appears on screen.

    It's not clear how your code is supposed to work; do you have an instance of ViewController in existence when tapDetected is called? If this is the case, and this is the ViewController whose button you want to alter the alpha of, then you need to have a reference to that instance of ViewController and call setAlphaToButton on it.

提交回复
热议问题