Chip Cary Chip Cary - 6 months ago 38
Objective-C Question

UIView setHidden not working

I am writing an app for the iphone and am attempting to create a view controller with two different views. So I have a subview created on top of the initial view in storyboard. I have created an outlet in the .h for the new view. I want to display the resultsView after the button is pressed so I have the view set to hidden in properties.

@interface ViewController : UIViewController
UIView *resultsView;
@property (nonatomic, retain) IBOutlet UIView *resultsView;
- (IBAction)buttonTapped:(id)sender;

In my .m I have the following code

#import "ViewController.h"

@interface ViewController ()


@implementation ViewController

@synthesize resultsView;

- (IBAction)scanButtonTapped:(id)sender
[resultsView setHidden = NO];

I have also tried

resultsView.hidden = NO;

Neither of these worked and I tried NSLog to retrieve the BOOL of resultsView.hidden and it was still YES.


If resultsView is NULL or nil, then you did not assign it properly in interface builder, or in code. Make sure you drag the outlet connection in your storyboard/xib file, or assign it in code somewhere like viewWillAppear

If the function isn't getting called, then the action is not linked up to the button in interface builder. To make sure it is connected properly, you can ctrl+click (or right click) and drag from the button to the view controller, and select scanButtonTapped from the "Sent actions" list that appears