Tag Archives: IOS 5

Prepare for Segue in IOS 5

I’ve been working on a few iPhone and iPad apps using IOS 5 and have been watching Paul Hegarty’s iPhone course at Stanford though iTunes U. I recommend watching it for anyone who is interested in IOS development as it’s as fantastic source of information and Paul is a great teacher.

One of the many useful things I found when first delving into the model view controller paradigm was the method that is called just before a Segue to another view controller prepareForSegue:

You can use this to set properties in the view controller you are about to segue to such as the delegate which is very useful.
You just need to set the identity of the segue in Xcode so it can be identified.

Here is a small snippet based on Paul’s example

-(void) prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender
{
    if ([segue.identifier hasPrefix:@"Next View"]) {
      
        //The segue is to the a View Controller called NextViewController
        (NextViewController *nvc =  (NextViewController  *) segue.destinationViewController;
       
       //Set properties in the view controller - note the views outlets are not set yet
        nvc.stringProperty1 = @"This Is Property 1";
      
         nvc.property2 = @"This Is Property 2";
       //Set self as the delegate
       nvc.delegate = self;
    }
}