Assignment #6 Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

When the user chooses a Virtual Vacation from the list, bring up a static table view with two choices: Itinerary and Tag Search.

In both storyboards add an additional table view controller, create a subclass for it and set it up in story board. Create a push segue from the prototype cell of the vacations table view controller to the new table view controller.

The tricky part of this task is to make the table static. Select the table view of the table view controller and change its content type from previously Dynamic Prototypes to Static Cells. Label the first cell “Itinerary”, the second “Tag Search” and delete the third cell.

The table needs to know which vacation has been selected (for now to display its name in the title, but in the future to tell the following controllers which vacation to use). Thus we need a model which holds that vacation and will display it in the title. … and make sure auto rotation works:

//  VacationTableViewController.h
@property (nonatomic, strong) NSString *vacation;

//  VacationTableViewController.m
@synthesize vacation = _vacation;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = self.vacation;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

Finally we let set the vacations view controller set the vacation model of the new table view controller:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [super prepareForSegue:segue sender:sender];
    if ([segue.identifier isEqualToString:@"Show Vacation"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];        
        [segue.destinationViewController setVacation:
            [self.vacations objectAtIndex:indexPath.row]];        
    }
}

The complete code for this task is available at github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.