In my IB I created a segue to push from one UIViewController (identifier = List) to another (identifier = Details). Then in
prepareForSegue
I do this to carry over some data for testing purposes:
Detail *detailsViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Details"];
NSLog(@"Current \"Details\" class in use: %@",detailsViewController);
NSLog(@"Prep Complete, Testing begins==============");
detailsViewController.TitleField.text = @"Random Text";
detailsViewController.DuedateField.text = [NSString stringWithFormat:@"%@",[NSDate date]];
detailsViewController.ReminderFieldOne.text = [NSString stringWithFormat:@"%@",[NSDate date]];
detailsViewController.ReminderFieldTwo.text = [NSString stringWithFormat:@"%@",[NSDate date]];
detailsViewController.NotesArea.text = @"Note 1: This doesnt seem to work.";
NSLog(@"Items from %@:",detailsViewController);
NSLog(@"Title Field = %@",detailsViewController.TitleField.text);
NSLog(@"Duedate field = %@",detailsViewController.DuedateField.text);
NSLog(@"Reminder field 1 = %@",detailsViewController.ReminderFieldOne.text);
NSLog(@"Reminder field 2 = %@",detailsViewController.ReminderFieldTwo.text);
NSLog(@"Notes = %@",detailsViewController.NotesArea.text);
NSLog(@"===============Testing Complete");
Yet almost all the NSLogs return (null) values from the same detailsViewController the data was sent to.
2012-02-08 13:38:53.016 TodoApp[10132:fb03] Items from <Detail: 0x6d70120>:
2012-02-08 13:38:53.017 TodoApp[10132:fb03] Title Field = (null)
2012-02-08 13:38:53.017 TodoApp[10132:fb03] Duedate field = (null)
2012-02-08 13:38:53.018 TodoApp[10132:fb03] Reminder field 1 = (null)
2012-02-08 13:38:53.019 TodoApp[10132:fb03] Reminder field 2 = (null)
2012-02-08 13:38:53.020 TodoApp[10132:fb03] Notes = (null)
I’ve been at it for a while now, to figure out why it’s (null). Does anyone have any clue why this happens? Am I missing something?
Thanks for your time!
EDIT: The Detail View thats edited and the one thats loaded seem defferent, but that does not explain why the logs return (null) coz the fetch data from the same Details view as the one thats edited.
2012-02-08 14:41:11.937 TodoApp[10567:fb03] Current "Details" class in use: <Detail: 0x6a883a0>
2012-02-08 14:41:11.937 TodoApp[10567:fb03] Prep Complete, Testing begins==============
2012-02-08 14:41:11.939 TodoApp[10567:fb03] Items from <Detail: 0x6a883a0>:
2012-02-08 14:41:11.940 TodoApp[10567:fb03] Title Field = (null)
2012-02-08 14:41:11.940 TodoApp[10567:fb03] Duedate field = (null)
2012-02-08 14:41:11.941 TodoApp[10567:fb03] Reminder field 1 = (null)
2012-02-08 14:41:11.942 TodoApp[10567:fb03] Reminder field 2 = (null)
2012-02-08 14:41:11.942 TodoApp[10567:fb03] Notes = (null)
2012-02-08 14:41:11.943 TodoApp[10567:fb03] ===============Testing Complete
2012-02-08 14:41:11.953 TodoApp[10567:fb03] View Loaded: <Detail: 0x6d1feb0>
Is there a way I can tell my app to load the instead?
Because the outlets are not getting initialized before -viewDidLoad method gets called. Create iVars for each value you want to store and assign them after the init method of destination controller. Then assign those values to outlets in viewDidLoad.
e.g.
in your destination controller’s .h file
Then
And in detailsViewController -viewDidLoad method