I’m debugging an iphone app and I’m seeing something I don’t understand fully.
Based on user’s selection, a UIView is being shown or hidden. Current code shows or hides the view with [view setHidden:NO] and [view setHidden:YES]. This doesn’t work: visually it’s as if these statements are simply ignored. However when I changed these to view.hidden = NO and view.hidden = YES respectively, everything is working as expected.
I was thinking that the two syntaxes are equivalent, but apparently not. For all other attributes (text, font, etc.), both work identically, so what’s so special about hidden?
EDIT: Here’s the copy/paste of some of my code. I’m working in XCode 4.3 with iPhone simulator 5.0
Here’s one example from my project.
IBOutlet UIView *panel; //Connected in interface builder
===========
- (void)makePanelVisible:(BOOL)visible
{
[panel setHidden:!visible]; //this does not work
panel.hidden = !visible; //this does work correctly.
}
Thinking back about this, I remember running into the same issue almost 3 years ago, when iPhone 3 (not even 3G) was all the rage. I’m not sure why this happens, but it does – so I just deal with it by setting the property using the “dot” notation. I guess, this is one of those “don’t fix it if it ain’t broken” things (ok, it is sort of broken, but there’s an easy way around it, so I’m using it).