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 for my segmented control:
Is this a good way to solve this???
If not - how do you do this in a proper way?
Thanks in advance!
MACloop
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