Testing if a UI element is hidden in an OCUnit test

Posted by Logan Serman on Stack Overflow See other posts from Stack Overflow or by Logan Serman
Published on 2012-09-13T21:36:13Z Indexed on 2012/09/13 21:37 UTC
Read the original article Hit count: 256

Filed under:
|
|
|
|

I have a button that is hidden under certain circumstances that I wish to test. The button is hidden with [theButton setHidden: YES] in the viewDidLoad method if it is appropriate. For simplicity, lets say that the button is hidden when the buttonIsHidden property is set to true in the view controller.

Right now I am trying the following:

self.viewController = [[ViewController alloc] init];
self.viewController.buttonIsHidden = YES;
[self.viewController loadView];

UIButton *theButton = [...] // function I wrote to retrieve the button based on it's touch up inside action

if (theButton) {
    NSLog(@"%c", theButton.hidden);
    return (theButton.hidden == true)
}

return NO;

It looks like the hidden property is not what it should be, the NSLog lines from the above code are blank. But, if I output another property like the height, it outputs the correct value so I know it is getting the right button.

How do I access the hidden property of the button in this case?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about xcode