PDA

View Full Version : Howto update the subview data of a navigation controller when I reuse it?




supertoto
Aug 2, 2008, 10:13 AM
Hi, dear fellows,

I am having a problem about using navigation controller and the sub views.

Here is the brief description about my program(Source code is too much to show, and I will describe the main idea behind my app.)

a. I created a UITabBarController with 8 sub views.
b. 6 of the 8 sub views are UINavigationController.
c. I created the UINavigationController by using initWithRootViewController.
d. I added a UITableView in the root view controller of the navigation controller and read some hierarchy data which is the top level of my data structure and supposed to be shown on on the table view [d].
e. I added another UIViewController which is works as same as the [d] one(That's means it also has an UITableView.), when I touch a cell in [d], I will push this subview [e] to the navigation controller and show the level 2 data of my data structure.

[Till here, it all works fine! Here comes the problem.]

f. When I touch the "Back" button in the table view [e], it correctly returns to the root view and shows the level 1 data. BUT, then it will be freeze and crashed in a few seconds. So I added a reference of the sub view controller [e] to the root view controller [d]. Then, the application will not be crashed any more, but the problem occurred : I CAN NOT update the sub view contents! It always only show the data when it was first appeared.

I know it's some kind of data cache, but how can I update the sub view when it will be used next time? I had tried [UIView setNeedDisplay] in the delegate method viewWillAppear in the view controller [e], but it didn't work. So, fellows, please give me some fresh air....

Thank you!



TripleJ
Aug 2, 2008, 11:02 AM
this might be a silly question, but did you remember to retain your definitions? eg. (nonatomic, retain)

supertoto
Aug 2, 2008, 11:25 AM
this might be a silly question, but did you remember to retain your definitions? eg. (nonatomic, retain)

yes, i have already used nonatomic and retain

supertoto
Aug 2, 2008, 12:43 PM
Further more, here is the implementation of the delegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath of the [d] view Controller(The root view controller of the navigation controller)


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
To conform to the Human Interface Guidelines, selections should not be persistent --
deselect the row after it has been selected.
*/
[tableView deselectRowAtIndexPath:indexPath animated:YES];

if (self.navigationController == nil){
NSLog(@"navigation Controller is NULL!!");
}else{
if (courseViewController == nil){
LevelSecondController *aLevelSecondController = [[LevelSecondController alloc] initWithNibName:@"LevelSecondView" bundle:nil];
aLevelSecondController.categoryID = indexPath.row;
self.levelSecondViewController = aLevelSecondController;
[self.navigationController pushViewController:levelSecondViewController animated:YES];
[aLevelSecondController autorelease];
}else{
levelSecondViewController.categoryID = indexPath.row;
[self.navigationController pushViewController:levelSecondViewController animated:YES];
}
}
}



Here is some other delegate method of [e] controller (the view controller which has a UITableView to show the second level data)


- (void) viewWillAppear{
[ownTableView reloadData];
}

- (void)viewWillDisappear:(BOOL)animated{
[ownTableView setNeedsDisplay];

}

supertoto
Aug 4, 2008, 01:44 AM
anybody got an idea?