Alexander Yakovlev
Alexander Yakovlev

Reputation: 510

Can't understand the storyboards in xcode 5

I can't understand the storyboards in xcode 5. I'm searching for the answers by doing manuals but nothing works, even simple storyboard scenes. Almost all of the manuals are on xcode 4.x, but I work in the fifth. As I understand there are some differences between the implementation of scenes in the xcode 4 and 5. I can't understand at all the principle of storyboards, and therefore do not understand why nothing works. Please help me to understand the difference between the xib and storyboard. What is the best for working and under what conditions? All the books which I have are about the IOS 6 and they're all with xib examples which I can't even run in the fifth xcode. Can't find adequate documentation on developer.apple.com, all confused. Аs I understand, the books about xcode 5 + IOS 7 will be released in a few months. Please, help me to make this scheme, the cells in the tableviews are static. Link to scheme https://www.dropbox.com/s/mwwfqgsj2d98exe/Scheme.jpg

Upvotes: 1

Views: 3066

Answers (1)

Tommie C.
Tommie C.

Reputation: 13181

Here is an explanation for storyboards in Xcode 5 and specifics on how to make the connections between different scenes as identified in your scheme outlined in the image below:

Starting with the big picture:

  1. To make segues between one scene or another you ctrl-drag from one view controller to a target view controller (you no longer need to ctrl-click from control to a different view)
  2. In the source scene (document outline view) click the segue created
  3. In the identity inspector create a unique name for the segue identifier
  4. Any control can now call the following view controller method to execute the segue - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  5. One can pass data between view controllers by implementing the following method on the source view controller:- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

So specific to your scheme:

Within the Storyboard: Inside the Document Outline (Editor > Show Document Outline):

Expand two scenes

  1. Ctrl-drag between ViewController1 to ViewController2
  2. In the source scene, click the segue created and set the identifier in the identity inspector
  3. In the source view controller, create the prepareForSegue described above to access and pass any data objects between view controllers (make sure you have a property on the target view controller, you use the segueIdentifier to control what data to send)
  4. In the action method for the two buttons call the respective segue using a different id for View2 and View5 [self performSegueWithIdentifier:@"MYSEGUE_ID" sender:btnObjectNilEtAl];
  5. To render segues to other view controllers just repeat the ctrl-drag process between a source and target view controller (View2 to View4/View5).
  6. To have segues engage from the tableview cell simply add the [self performSegueWithIdentifier:@"MYSEGUE_ID" sender:btnObjectNilEtAl]; code into the didSelectRowAtIndexPath method.

Here are some code samples to get you started:

// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifier] isEqualToString:@"showDealDetail"])
    {
        // Get reference to the destination view controller
        DealDetailViewController *dvc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
        [dvc setDetailObject:(NSManagedObject*)sender];
    } else if ([[segue identifier] isEqualToString:@"showActivityDetail"])
    {
        ActivityDetailViewController * advc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
        [advc setDetailObject:(NSManagedObject*)sender];
    } else if ( [[segue identifier] isEqualToString:@"showMatchDetail"])
    {
        MatchDetailViewController * mdvc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
        [mdvc setDetailObject:(NSManagedObject*)sender];
    }
}

From ViewController1 within the two button action methods call:

 //execute manual segue
        [self performSegueWithIdentifier:@"showAlternate" sender: self];

Scheme

Upvotes: 2

Related Questions