-4

I have viewA and viewB inside of a containerview.

I passed Var from a viewA to the containerviewcontroller by delegate. I need to pass it from my containerviewcontroller to tableviewcontroller. I tried two ways, one way i was able to pass it, but I can't gain access to the viewA inside of the container view. I can open viewA with the second way, but the Var doesn't get passed.

Please help.

My storyboard flow is as follow.

containerview -> tabbarviewcontroller ->navigationviewcontroller -> tableviewcontroller

(void)openSavedProjectAt:(NSNumber *)index
{
    //delegate from another class   
    // works, and index value gets passed, but menu button doesn't work after, cuz didn't push with container?
    /*
    IncomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"incomeList"];
    [incomeNav pushViewController:vc animated:YES];
    vc.projectIndexToOpen = index;
    */  
    // the value doesn't get passed, but everything else works
    /*
    IncomeViewController *vc = [[IncomeViewController alloc]init];    
    vc.projectIndexToOpen = index;
    */    
    [self menuButtonPushed]; // close side menu
}
Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
gt3240
  • 3
  • 4
  • Its NOT a duplicate - he know how to pass, its that he's having problems with it, that is his question, not how to in general, why he's having problems in his specific case. – Gruntcakes Apr 18 '14 at 04:05

1 Answers1

0

If this is your structure,

containerview -> tabbarviewcontroller ->navigationviewcontroller -> tableViewController

think about the relationships you have and put them together. The tabBarController is the containerViewController's childViewControllers[0] (assuming that you have only one child). The navigation controller is one of the controllers in the tab bar controller's viewControllers array -- if it's the first one then viewControllers[0]. The table view controller is the navigation controller's topViewController, so putting that all together, you get,

TableViewController *tvc = (TableViewController *)[(UINavigationController *)[(UITabBarController *)self.childViewControllers[0] viewControllers][0] topViewController];

That's kind of ugly to parse, so it would be easier to read as multiple lines,

UITabBarController *tbc = self.childViewControllers[0];
UINavigationController *nav = tbc.viewControllers[0];
TableViewController *tvc = (TableViewController *)nav.topViewController;

With the tvc reference, you can now pass the object you want.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Thanks for the help. Seems to work, but I'm not sure if the Var has been passed, is there a way to reload the whole talbeviewcontroller? – gt3240 Apr 18 '14 at 05:33
  • @gt3240, if you want to reload the whole table, use [self.tableView reloadData]; – rdelmar Apr 18 '14 at 05:36
  • reloadData only reloads the table, is there a method to reload the whole view? – gt3240 Apr 18 '14 at 14:05
  • @gt3240, sorry, I misread your question. Why do you wan to reload the whole controller? What else do you need to do there other than updating the table view? – rdelmar Apr 18 '14 at 15:00
  • I need to update a variable which is used in the tableview to load the correct contents. – gt3240 Apr 18 '14 at 16:30
  • @gt3240, which you do by passing the new value to that variable using the reference tvc. You don't need to reload the whole controller to do that. – rdelmar Apr 18 '14 at 16:37
  • I have a list in the side menu. When I select a row, it send a nsnumber to the tableviewcontroller to show the correct list. However, the nsnumber gets passed, but the nsnumber is already loaded in the tvc, so I want to reload that with the new one. Thanks for the help. – gt3240 Apr 18 '14 at 16:39