0

sorry for my bad English

i need to pass data from my First View Controller to Front View Controller of SWRevealViewController

in my First View Controller i do this code

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"menu"]) {
        SWRevealViewController *sw = (SWRevealViewController *) segue.destinationViewController;

        // error is here i get nav with nil
        UINavigationController *nav = (UINavigationController *)sw.frontViewController;
        FrontViewController *home = (FrontViewController *) nav.topViewController;
        home.passed_student = selected_student;



}
}

enter image description here

Mohammad Shaker
  • 185
  • 1
  • 15
  • 1
    UINavigationController *nav = (UINavigationController *)sw.frontViewController; here your frontViewController is a property of SWRevealViewController? – iHulk Sep 23 '14 at 07:38
  • yes , its diffrent from Class Called FronViewController – Mohammad Shaker Sep 23 '14 at 07:40
  • 1
    I think your property frontViewController is used before it is initialise as UINavigationController inside SWRevealViewController . – iHulk Sep 23 '14 at 07:44

1 Answers1

2

In storyBord no object(view controller) is created untill it is presented using segue or accessed some other way so here in your code your are presenting the SWRevealViewController but try to access the object of FrontViewController which is not in memory.

So first you should pass your selected_student to your SWRevealViewController then from here to FrontViewController because you can access the object of FrontViewController from here during presenting it using segue. This is the simplest way of doing it.

iHulk
  • 4,869
  • 2
  • 30
  • 39
  • i am new to ios , so how can i do that – Mohammad Shaker Sep 23 '14 at 07:53
  • 1
    Right now you are presenting the object of SWRevealViewController from your FirstViewConroller and you want to pass the data of selected_student one step ahead to FrontViewController. For this you will need the object of FrontViewController that can be accessed here by giving the id to this FrontViewController inside your storyBoard and then access it here using that id. I will provide you the code in few minutes. – iHulk Sep 23 '14 at 07:59
  • 1
    I had updated the answer. If it is still not working please let me know. – iHulk Sep 23 '14 at 08:10
  • reason: 'Storyboard () doesn't contain a view controller with identifier 'frontVC'' i change to 'sw_front' but it crash , what identifier i should put here – Mohammad Shaker Sep 23 '14 at 08:22