Hi,
I am surely doing something completely stupid here, hopefully someone can tell me what! In summary I would like to programmatically toggle a subview when a button (I'll use a segmented button) is clicked. It need not animate. Ideally I'd load the contents of these views from a nib.
I am pushing a UIViewController subclass, initialised from a nib, on to a navigationController. This view controller & it's "default" view display ok. This nib contains:
File's Owner [Class=my view controller subclass]
First Responder
View
--Bar Segmented Control
--View //this is the 'subview' whose content I want to toggle
Perhaps I've made a mistake with my IB outlets? They are hooked up as follows:
switchableView <--> View
view <--> View
And where switchableView
is declared:
IBOutlet UIView *switchableView;
...
@property (nonatomic, retain) UIView *switchableView;
I am stuck at replacing the contents of this UIView. First off, I just want to set it to a default when the view first comes to life. Once I've got that, swapping it to something else should be easy as I can already capture the event generated by the segmented button. Can someone please tell me what I am doing wrong?
- (void)loadView {
NSLog(@"loadView invoked");
[super loadView];
UIView *view = [[UIView alloc] init];
UILabel *label = [[UILabel alloc] init];
label.text = @"Segment1";
[view addSubview:label];
[switchableView addSubview:view]; //this is what I can't work out
[view release];
[label release];
}
That method is invoked (as is viewDidLoad
), but neither help. I guess that I am doing [switchableView addSubview:view]
wrong. I've also tried switchableView = view
, but a long time in the safety of Java and Perl makes me not 100% sure whether that is right to try or not!
Here's hoping someone can set me straight. Thanks in advance,
Paul