Howto update the subview data of a navigation controller when I reuse it?

Discussion in 'iOS Programming' started by supertoto, Aug 2, 2008.

  1. supertoto macrumors newbie

    Jul 29, 2008
    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!
  2. TripleJ macrumors regular

    Jul 30, 2008
    this might be a silly question, but did you remember to retain your definitions? eg. (nonatomic, retain)
  3. supertoto thread starter macrumors newbie

    Jul 29, 2008
    yes, i have already used nonatomic and retain
  4. supertoto thread starter macrumors newbie

    Jul 29, 2008
    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!!");
    		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];
    			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];
  5. supertoto thread starter macrumors newbie

    Jul 29, 2008

Share This Page