1

How can I pass data between a Navigation Controller and a Table View Controller? I have tried prepareForSegue method but it doesn't work.. I have tried to put a breakpoint to see if the flow calls this method but it seems that the prepareForSegue of my Navigation Controller class is never called. Here is some sample of code :

NavController.h :

@interface NavController : UINavigationController

@end

NavController.m :

- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
    TableViewController *destViewController = (TableViewController*)segue.destinationViewController;
    destViewController.title = @"Home";
    destViewController.URLValue = @"http://www.example.com";
}

TableViewController.h :

@interface TableViewController : UITableViewController 

@property (nonatomic, strong) NSString *URLValue;

@end
Moussa
  • 3,789
  • 5
  • 24
  • 41
  • How is your segue defined, specifically what object does it come from in your UI design? – Phillip Mills Jul 31 '14 at 13:20
  • My segue comes from NavController and the destination is TableViewController. The link between NavController and TableViewController is "root view controller" – Moussa Jul 31 '14 at 13:25
  • As far as I know, that's not a segue. It's defined as 'relationship' and has no segue attributes in interface builder. – Phillip Mills Jul 31 '14 at 13:35

1 Answers1

0

It sounds like the navigation controller is your root view controller (ie, if you select the navigation controller scene and inspect its details in Xcode, the "Initial Scene" checkbox should be checked). Because it's the initial scene and is arrived in only one way, try setting default values in viewDidLoad: on your TableViewController.

azsromej
  • 1,579
  • 12
  • 14
  • Hi I thought about using `viewDidLoad:` but it doesn't work with the rest of the application. Finally I solved my issue using that : `UINavigationController *navController = [segue destinationViewController]; TableViewController *destViewController = (TableViewController *)([navController viewControllers][0]); destViewController.title = @"Home"; destViewController.URLValue = @"http://www.example.com";` – Moussa Jul 31 '14 at 13:47