Hello,
I am not sure that I understand this alright.
I have a tableViewController letting the user navigate by clicking one of the cells. In the didSelectRowAtIndexPath method, I do the following:
I have the following definition in the DetailedViewController.h file:
In the viewDidLoad in the DetailedViewController I define the following:
To enable the use of the segmentedControl:
To release and free memory:
The questions:
1) Everytime when I push this view is the viewDidLoad called. Is the viewDidUnload and dealloc called when the user leaves the view ie. presses the backbutton?
2) The definition of the segmentedControl is somthing that I have thought alot about. I use assign in the .h file. After that I create the object in the viewDidLoad. I release the object in the dealloc. This means that everytime I call the viewDidLoad, ie when the viewcontroller is pushed, a new choice object is created. Is this a godd solution? How could I do this differently? Is this leaking?
Thanks in advance!
MACloop
I am not sure that I understand this alright.
I have a tableViewController letting the user navigate by clicking one of the cells. In the didSelectRowAtIndexPath method, I do the following:
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
vc= [[DetailedViewController alloc] initWithNibName:@"DetailedViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
I have the following definition in the DetailedViewController.h file:
Code:
UISegmentedControl *choice;
...
@property(nonatomic,assign) UISegmentedControl *choice;
In the viewDidLoad in the DetailedViewController I define the following:
Code:
choice = [[UISegmentedControl alloc]initWithItems:items];
choice.segmentedControlStyle = UISegmentedControlStyleBar;
choice.selectedSegmentIndex = 0;
[choice addTarget:self action:@selector(segmentedControlValueChanged) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = choice;
To enable the use of the segmentedControl:
Code:
- (void)segmentedControlValueChanged {
selectedUnit = choice.selectedSegmentIndex;
[self updateView];
}
- (void)updateView {
if (selectedUnit == 0) {
[aView setHidden:YES];
[anotherView setHidden:NO];
}
if (selectedUnit == 1) {
[aView setHidden:NO];
[anotherView setHidden:YES];
}
}
To release and free memory:
Code:
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.aView = nil;
self.anotherView = nil;
}
- (void)dealloc {
[super dealloc];
[aView release];
[anotherView release];
[choice release];
}
The questions:
1) Everytime when I push this view is the viewDidLoad called. Is the viewDidUnload and dealloc called when the user leaves the view ie. presses the backbutton?
2) The definition of the segmentedControl is somthing that I have thought alot about. I use assign in the .h file. After that I create the object in the viewDidLoad. I release the object in the dealloc. This means that everytime I call the viewDidLoad, ie when the viewcontroller is pushed, a new choice object is created. Is this a godd solution? How could I do this differently? Is this leaking?
Thanks in advance!
MACloop