I have a simple method that checks for the superview of a view, and returns a BOOL. However, intermittently the method fails to produce the right answer (or at least the answer Iʻm expecting).
The method is:
-(BOOL) isTheViewShowing
{
return (BOOL) [theView superview];
}
There is a Tap Gesture that removes the view, and I logged the following (when the undesirable happens):
isTheViewShowing: NO
theView: <UIView: 0x3c1a10; frame = (0 232; 320 135); clipsToBounds = YES; layer = <CALayer: 0x365480>>,
superView: <UIView: 0x392400; frame = (0 0; 320 367); autoresize = W+H; layer = <CALayer: 0x35fe90>>
As the log shows the superView exists, but why is the cast failing?
Note that the low order byte of
superviewis 0x00. I haven’t really looked into what happens when you try to cast a pointer to aBOOL, but since aBOOLis essentially acharI wouldn’t be at all surprised if the compiler just looks at the low order byte. Try this instead:That’s better on two counts: 1) it actually works, and 2) it better communicates what you’re trying to do.