Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ()

@end

@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.

like image 974
Chip Cary Avatar asked Dec 27 '22 20:12

Chip Cary


2 Answers

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

like image 71
Dan F Avatar answered Jan 05 '23 14:01

Dan F


Another option - check that you run your [? setHidden:] code in UIThread

like image 41
A. Petrov Avatar answered Jan 05 '23 15:01

A. Petrov