Kutay Demireren
Kutay Demireren

Reputation: 650

How to make work preparForSegue :sender: XCode 6?

In my app, I use segment to switch in three view. Every segmment represented with container view and they become hidden or appear according to segment. That is how my the design works, and it works well. You can find the picture below, so you can understand the structure more:

enter image description here

I'm having trouble with giving an instance (namely, user) created in the view controller to segment's container's view controller. I created user in the user and assign it the values. user instance has the values, I checked it. So, as usual to give with segue, I tried prepareForSegue:sender method to achieve my purpose. In the viewLoad method of the table views(you can find the table views: each of them are attached to its own container in the view controller that has segment. There are 3 containers.) user instances of table views are null. I can't give it, basically. Shouldn't the view controller pass the user value? It might being container view, but still I think it should be :) Anyway, please find below what I have written so far:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

        UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
        DovizTableViewController *controller = (DovizTableViewController *)navController.topViewController;
        controller.user = self.user;
}

Upvotes: 2

Views: 87

Answers (2)

App Dev Guy
App Dev Guy

Reputation: 5536

You would remove the sender part of your code.

It should look like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue{ 
    //your code 
    //check if the next view exists by checking for the id
    if ([[segue identifier] isEqualToString:@"Segue_Name"])
    {
        DovizTableViewController *controller = [segue destinationViewController];
        controller.user = self.user;
    }
}

Upvotes: 2

Sana
Sana

Reputation: 557

Try this.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
            {
                // Get reference to the destination view controller
                 DovizTableViewController *controller = [segue destinationViewController];

                // Pass any objects to the view controller here, like...
                controller.user = self.user;
            }
    }

Hope it helps.

Upvotes: 0

Related Questions