MASExampleListViewController.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // MASExampleListViewController.h
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 21/07/13.
  6. // Copyright (c) 2013 cloudling. All rights reserved.
  7. //
  8. #import "MASExampleListViewController.h"
  9. #import "MASExampleViewController.h"
  10. #import "MASExampleBasicView.h"
  11. #import "MASExampleConstantsView.h"
  12. #import "MASExampleSidesView.h"
  13. #import "MASExampleAnimatedView.h"
  14. #import "MASExampleDebuggingView.h"
  15. static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
  16. @interface MASExampleListViewController ()
  17. @property (nonatomic, strong) NSArray *exampleControllers;
  18. @end
  19. @implementation MASExampleListViewController
  20. - (id)init {
  21. self = [super init];
  22. if (!self) return nil;
  23. self.title = @"Examples";
  24. self.exampleControllers = @[
  25. [[MASExampleViewController alloc] initWithTitle:@"Basic"
  26. viewClass:MASExampleBasicView.class],
  27. [[MASExampleViewController alloc] initWithTitle:@"Using Constants"
  28. viewClass:MASExampleConstantsView.class],
  29. [[MASExampleViewController alloc] initWithTitle:@"Composite sides"
  30. viewClass:MASExampleSidesView.class],
  31. [[MASExampleViewController alloc] initWithTitle:@"Basic Animated"
  32. viewClass:MASExampleAnimatedView.class],
  33. [[MASExampleViewController alloc] initWithTitle:@"Debugging helpers"
  34. viewClass:MASExampleDebuggingView.class],
  35. ];
  36. return self;
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
  41. }
  42. #pragma mark - UITableViewDataSource
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. UIViewController *viewController = self.exampleControllers[indexPath.row];
  45. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMASCellReuseIdentifier forIndexPath:indexPath];
  46. cell.textLabel.text = viewController.title;
  47. return cell;
  48. }
  49. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  50. return self.exampleControllers.count;
  51. }
  52. #pragma mark - UITableViewDelegate
  53. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  54. UIViewController *viewController = self.exampleControllers[indexPath.row];
  55. [self.navigationController pushViewController:viewController animated:YES];
  56. }
  57. @end