// // Created by Jesse Squires // http://www.jessesquires.com // // // Documentation // http://cocoadocs.org/docsets/JSQMessagesViewController // // // GitHub // https://github.com/jessesquires/JSQMessagesViewController // // // License // Copyright (c) 2014 Jesse Squires // Released under an MIT license: http://opensource.org/licenses/MIT // #import "TableViewController.h" @implementation TableViewController #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; self.title = @"JSQMessagesViewController"; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 2) { return 1; } return 2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } if (indexPath.section == 0) { switch (indexPath.row) { case 0: cell.textLabel.text = @"Push via storyboard"; break; case 1: cell.textLabel.text = @"Push programmatically"; break; } } else if (indexPath.section == 1) { switch (indexPath.row) { case 0: cell.textLabel.text = @"Modal via storyboard"; break; case 1: cell.textLabel.text = @"Modal programmatically"; break; } } else if (indexPath.section == 2) { switch (indexPath.row) { case 0: cell.textLabel.text = @"Settings"; break; } } return cell; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { switch (section) { case 0: return @"Presentation"; case 2: return @"Demo options"; default: return nil; } } - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { return (section == [tableView numberOfSections] - 1) ? @"Copyright © 2014\nJesse Squires\nMIT License" : nil; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { switch (indexPath.row) { case 0: [self performSegueWithIdentifier:@"seguePushDemoVC" sender:self]; break; case 1: { DemoMessagesViewController *vc = [DemoMessagesViewController messagesViewController]; [self.navigationController pushViewController:vc animated:YES]; } break; } } else if (indexPath.section == 1) { switch (indexPath.row) { case 0: [self performSegueWithIdentifier:@"segueModalDemoVC" sender:self]; break; case 1: { DemoMessagesViewController *vc = [DemoMessagesViewController messagesViewController]; vc.delegateModal = self; UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc]; [self presentViewController:nc animated:YES completion:nil]; } break; } } else if (indexPath.section == 2) { switch (indexPath.row) { case 0: [self performSegueWithIdentifier:@"SegueToSettings" sender:self]; break; } } } #pragma mark - Segues - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"segueModalDemoVC"]) { UINavigationController *nc = segue.destinationViewController; DemoMessagesViewController *vc = (DemoMessagesViewController *)nc.topViewController; vc.delegateModal = self; } } - (IBAction)unwindSegue:(UIStoryboardSegue *)sender { } #pragma mark - Demo delegate - (void)didDismissJSQDemoViewController:(DemoMessagesViewController *)vc { [self dismissViewControllerAnimated:YES completion:nil]; } @end