Wednesday, September 12, 2012

StoryBoard and screen flow

At first, I was struggling with StoryBoard and wonder how to jump from one screen to another. After some research in the web, I found out that it is quite straight forward. But, you might be very confuse if you were came from Microsoft .Net which has different way to handle the screen flow. Let's try it out.

First, you need to create a new project in XCode and add a few view controllers as shown below:

Stroyboard


Then, design the main view as shown below. Two buttons and one segment control.



Below is the code that handle the on click event for a button which will navigate to another screen. The "auto flow over" button does not handle the click event.

- (IBAction)manual_push_onclick:(id)sender {
  
    NSInteger i = [self.view_selection selectedSegmentIndex];
    if (i == 0)
    {  //show view 1
        [self performSegueWithIdentifier:@"manualSegue" sender:self];
    }
    else if (i == 1) {
        // show  view 2
        [self performSegueWithIdentifier:@"manualSegue2" sender:self];
    }
    else if (i == 2)
    {
        // jump 1 level down (in segue) to another view.
        // goto 'View Controller' in storyBoard -> then set the 'Identifier'.
        CAnotherViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"anotherSegueViewId"];
        [self.navigationController pushViewController:vc animated:NO];
       
     }
    else
    {
        // goto 'View Controller' in storyBoard -> then set the 'Identifier'.
        // this view does not have any link with the main view controller.
        CFloatingViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"floatingViewId"];
        [self.navigationController presentModalViewController:vc animated:NO];
    }
}

31-May-2013
If you are wondering where to set the "anotherSegueViewId", attached with the screen snapshot. You need to open the storyboard and then select your view controller. Then, goto "Custom Class" and look for "Identity" section. Key in the storyboard ID.

To set the segue ID:


1 comment:

  1. This blog post is really great; the quality information of this post is genuinely incredible.
    Magento Development Company | web design and development company

    ReplyDelete