views:

1640

answers:

2

I have the next question:

In my project I have the next:

UItabbarController

....Some UINAvigationControllers....

*(1) UINavigationController

  UIViewController (UItableView) - When select one row it goes to...(by push) to:

              UIViewController (UItableView) - And here the same than before, for each row i open a new tableview....

My problem is when i click in the tab bar item, I see the viewController view like last time that i saw this, and no reload to the *(1) first view another time( like i would like)

Where I need to write sth for each time that i click in a tab bar item i reload the first view of this tab bar item.

PD: I have the call: [theTableView reloadData]; in method "viewWillAppear".

The thing I'm doing is: In my navigation Controller I have a View Controller (like tableview) and when i click in one row, in the "didSelectRowAtIndexPath" method I create another View Controller calling "myController" and i push this element like this ( [[self navigationController] pushViewController:myController animated:YES];) And this for each time i click in one row in the next tables.

Then I think the problem is not to reload the table view in the method viewWillAppear, it's to take out from the screen the next views controller that I inserted to the root one.

I'm rigth?

IN RESUME:

My app has the next:

  • Tab bar to move between screens
  • Navigation inside each tab bar (as far as you want), why? because all the tabBarItems show Tables, and if you click in one row you open another table,.....

My problem then is that I would like to come back to the 1st Main table when i click in the tab bar. For the moment the app doesn't do this, it continue in the scree(table view) that was the last visit in this tab. (Is not completely true, because if i click two time, Yes, it comes back but don't enter in the "viewWillLoad" or "didSelectViewController" methods, because i made NSLogs and it doesn't show them).

The sketche can be this:

AppDelegate -> WelcomeScreen ->VideosTableViewController ->RElatedVideosTableViewController -> ..... ..... ....

The 1st thing is to show the Welcome screen (not so important, only some buttons) and in this class i have the TabBArController initialized with "localViewControllersArray" that is a NSMutableArray of NavigationControllers each initialized with one ViewController .

Then when i press one of the buttons in this welcome Screen i sho the tab bar Controller (Shows the VideosTableViewController)

In the next step, when I click in one row, in "DidSelectRowAtIndexPath" I create a RElatedVideosTableViewController, and I push this by "[[self navigationController] push....: "The relatedvideo table view i create" animated:YES];

AND I ALSO HAVE:

Add: UITabBarControllerDelegate Add:

  • (void)tabBarController:(UITabBarController*)tabBarController didEndCustomizingViewControllers: (NSArray*)viewControllers changed:(BOOL)changed { }

  • (void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController { if ([viewController isKindOfClass:[UINavigationController class]]) { [(UINavigationController *)viewController popToRootViewController:NO]; [theTableView reloadData]; NSLog(@"RELOAD"); } }

And at the initialization of the class: [super.tabBarController setDelegate:self];

But in the console I don't see the NSLog I'm making then is not going in this method.

A: 

Make your app delegate the tab bar controller's delegate, either in Interface Builder or in code:

- (void)applicationDidFinishLaunching
{
    ...
    self.tabBarController.delegate = self;
}

Then, when the tab bar switches to a different view, you get notified, at which point you pop to the root of the selected nav controller thus:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
      if ([viewController isKindOfClass:[UINavigationController class]])
      {
              [(UINavigationController *)viewController popToRootViewController:NO];
      }
}

Each view controller should have its own table view, so I don't know what you are trying to do by the reload.

Daniel Dickison
Im trying the reload because i want to use this to call a conection method each time i show the tables.
I added this to my code, bt continue doing the same, without enter in the didSelectViewController method.Note that between my appdelegate and the rest, i have a welcomeScreen viewcontroller, then where i declare the tabbarcontrolelr and where i put the line: self.tabbarController.delegate=self; is in this class.I dont know if this make some difference.
Put a break point on the line where you set the delegate. If it's not getting called, you (obviously) need to put it elsewhere. Perhaps you're putting it in an init method that doesn't get called.
Daniel Dickison
I declare this: self.tabBarController.delegate = self;and is doing this line, i checked:)
Now i can enter in the didSelectViewController, but this doesn't take out of the screen the view.
A: 
  • (void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController { NSLog(@"In WelcomeScreen -> didSelectViewController");

    if ([viewController isKindOfClass:[UINavigationController class]]) { NSLog(@"In WelcomeScreen -> IF -> didSelectViewController"); [(UINavigationController *)viewController popToRootViewController:YES]; NSLog(@"Out WelcomeScreen -> IF -> didSelectViewController");

    } NSLog(@"Out WelcomeScreen -> didSelectViewController"); }

I have: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UINavigationController popToRootViewController:]: unrecognized selector sent to instance

Nos i'm so confused. Should I put the code for this method and the <...Delegate> in the class that have the UITabBArController* or can i do this in one "subclass" type UIViewController??