1

This is probably the most frustrating situation I've dealt with, and it probably has the simplest solution.

I've got this UIButton storeB that gets properly initialized during the viewDidLoad: call of my UIViewController. Before I create the button, I create 5 other buttons.

During viewDidLoad:, I run this method called setupFBConditions which determines whether my forwardB button object should have an alpha of 0.5 with userInteractionEnabled set to 0. When this is the case, the button looks and performs the way it's supposed (essentially, like it's not there).

Furthermore, during this particular animation that is performed on one of my UIView objects, I decided to set the userInteractionEnabled property of my restartB object to 0 (so that no interaction occurs during the animation. That performance is also successful.

However, when I decide to write:

storeB.userInteractionEnabled = NO;
storeB.alpha = 0.5;

at the start of the animation (with the intention to keep this state till the game finishes or restartB is tapped again), and NSLog the button object, the log says that the userInteractionEnabled property is NO and alpha is 0.5, just like it should be. However, at no point do these properties get reflected to the UI.

storeB is my not even my last view to be added to the hierarchy (although it is the last UIButton). I have no idea why these changes are not taking effect.

I'm not going to post any more code because there's nothing to post besides the two lines above. It's that apparently simple of a problem + solution.

************ UPDATE **************

Here is the log report at the end of one of my swipe gesture actions (after storeB.userInteractionEnabled = NO;):

<UIButton: 0x1585ae80; frame = (270 8; 42 42); alpha = 0.5; opaque = NO; 
userInteractionEnabled = NO; layer = <CALayer: 0x15899da0>>  
<UIView: 0x1592bba0; frame = (0 0; 320 568); layer = <CALayer: 0x15934ae0>>

The frame is correct, the alpha and interaction settings are correct, and the superview frame (0,0,320,568) is exactly what it's supposed to be.

*********** SECOND UPDATE **************

In case anyone finds this useful...check the _retainCount property of your UIView/UIButton and see if it looks unusually high when taking into account all the operations done to the object. My retain count was 4 when it should have been 2, so every time I changed the property (of what I thought was my first instance of storeB), it was actually only affecting the second instance (that I didn't even know existed).

  • 1
    Where are these two lines of code? You need provide more context by providing more code. – rmaddy Dec 05 '16 at 20:45
  • 1
    Lots of problems look like this: "I have a handle to a view and when I do something to it, that something isn't reflected in the UI". Most of the time, the cause is that you don't have a handle to the view you're looking at in the UI. It's either nil or some other view. NSLog storeB and see if (a) it is non-nil, (b) the superview is the view controller's view and (c) if the frame makes sense. – danh Dec 05 '16 at 20:52
  • In addition to what @danh said, sometimes you have to layout the view again after making some changes. The under the hood draw order workings aren't always intuitive. Try adding [storeB layoutIfNeeded]; under your changes. If you are accessing the button you think you are, this will likely work. If you're accessing nil like danh suggested, it won't do anything for you. – Jake T. Dec 05 '16 at 21:37
  • To @danh and @Jake T., I provided an update in the post, see if anything looks odd. To me, nothing looks out of place, the frame values are correct and the property settings are good. I tried `[storeB layoutIfNeeded]` but with no success. My initial assumption was that `storeB` lost it's values after the animation section of my code, but that's not the case. – Anthony Shintoluggenprog Dec 05 '16 at 21:57
  • "it was actually only affecting the second instance (that I didn't even know existed)." This is an example of the view you were checking in code not being the view that you were seeing on the UI. – danh Dec 06 '16 at 00:30
  • Exactly, and I've never experienced that type of situation until now, otherwise I would've thought about that possibility. Thanks for the help, Dan – Anthony Shintoluggenprog Dec 06 '16 at 18:40

0 Answers0