G McLuhan
G McLuhan

Reputation: 392

How can you hide a segmented controller?

I have tried hiding a segmented controller just like a button or label can be hidden in XCode. It's intended to be hidden/shown when touching a parent segmented controller above. This Code would work with Buttons or Labels:

mySegmContr.hidden = YES;

But it just won't work for segmented controllers. Can you help me out?

Upvotes: 0

Views: 1511

Answers (2)

hodji
hodji

Reputation: 82

If you create a property for the segment controller you can do more stuff with it like changing it's location, resizing it and want you want hiding it.

In your .h file do this

UISegmentedControl *mySegment;
@property (nonatomic, retain) UISegmentedControl *mySegment;

-(void) createMySegment;

In your .m file do this

@synthesize mySegment;


- (void) createMySegment     {  
if ([self mySegment] == nil) {      
    NSArray *buttons = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
    UISegmentedControl *segName = [[UISegmentedControl alloc] buttons];  
    [self setMySegment:segName];
    [segName release]; 
    segName.frame = CGRectMake(110, 62, 120, 25);           
    segName.segmentedControlStyle = UISegmentedControlStyleBar;
    segName.momentary = NO;
    segName.selectedSegmentIndex = 0;
    [segName addTarget:self
                action:@selector(pickMethod:)
      forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segName];             
} 

}

NOTE: With "setMySegment" above make sure you use a capital first letter which is M in "mySegment". Then when you want to hide it use this. Don't for get to dealloc mySegment.

[[self mySegment] setHidden:YES];

Upvotes: 0

G McLuhan
G McLuhan

Reputation: 392

I figured out that you can use a simple UIView in which you put the things you want to hide. The UIView can then be hidden with

myView.hidden = YES;

still I found no way to hide a segmented control directly.

Upvotes: 2

Related Questions