Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACloop

macrumors 6502
Original poster
Hello,
I intend to use a tableView in an App. When the user clicks on a cell, antoher viewcontroller is created and it slides in from right. This works fine.

The problem is:
- The view in this viewcontroller created must include 2 subviews. One map and one table. When the view is loaded, the table should be displayed. When clicking on a segmented control a switching between the two subviews is enabled. So, how should I add those subviews? They are objects of UIViewController subclasses defined by me and my problem is to know how and when I shall create those views. Everytime the viewcontroller is created ie. the user click on the initial tabel cell, the init and the ViewDidLoad method are called. This means that if I create and add those subviews in one of those methods, they will be created everytime...? Is that good? I know that they may be relased and the classes may be cleaned up when the user leave them, but somehow I do not have a good feeling on creating them over and over again...? I would add the subviews in ViewDidLoad or in the init-method like this:
Code:
VC *vcTable = [[VC alloc]initWithNibName:@"VCTablenib" bundle:nil]);
self.table = vcTable.view;//table is retained and @synthezised
[vcTable release];
[self.view addSubview:table];
//add some data to this table
//perhaps reload it again

VC *vcMap = [[VC alloc]initWithNibName:@"VCMapnib" bundle:nil]);
self.map = vcMap.view;//map is retained and @synthezised
[vcMap release];
[self.view addSubview:map];
//call method for the map to add annotations on map

Code for my segmented control:
Code:
- (void)segmentedControlValueChanged {
	selectedUnit = (NSUInteger*)mapOrList.selectedSegmentIndex;
	[self updateView];
}

- (void)updateView {
	if (selectedUnit == (NSUInteger*)0) {
		[map setHidden:YES];
		[table setHidden:NO];
	}
	if (selectedUnit == (NSUInteger*)1) {
		[map setHidden:NO];
		[table setHidden:YES];
	}
}


Is this a good way to solve this???
If not - how do you do this in a proper way?
Thanks in advance!
MACloop
 
If you are using a nib for this view controller then simply create the two views in that nib. Your use of two other nibs makes no sense.

If I understand you the two views will not be visible at the same time. That's fine. You can hide/show the views if you like. Or you can make both views top level objects in the nib if you like.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.