MASExampleListViewController.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #import "MASExampleLabelView.h"
  16. #import "MASExampleUpdateView.h"
  17. #import "MASExampleRemakeView.h"
  18. #import "MASExampleScrollView.h"
  19. #import "MASExampleLayoutGuideViewController.h"
  20. #import "MASExampleArrayView.h"
  21. #import "MASExampleAttributeChainingView.h"
  22. #import "MASExampleAspectFitView.h"
  23. #import "MASExampleMarginView.h"
  24. static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
  25. @interface MASExampleListViewController ()
  26. @property (nonatomic, strong) NSArray *exampleControllers;
  27. @end
  28. @implementation MASExampleListViewController
  29. - (id)init {
  30. self = [super init];
  31. if (!self) return nil;
  32. self.title = @"Examples";
  33. self.exampleControllers = @[
  34. [[MASExampleViewController alloc] initWithTitle:@"Basic"
  35. viewClass:MASExampleBasicView.class],
  36. [[MASExampleViewController alloc] initWithTitle:@"Update Constraints"
  37. viewClass:MASExampleUpdateView.class],
  38. [[MASExampleViewController alloc] initWithTitle:@"Remake Constraints"
  39. viewClass:MASExampleRemakeView.class],
  40. [[MASExampleViewController alloc] initWithTitle:@"Using Constants"
  41. viewClass:MASExampleConstantsView.class],
  42. [[MASExampleViewController alloc] initWithTitle:@"Composite Edges"
  43. viewClass:MASExampleSidesView.class],
  44. [[MASExampleViewController alloc] initWithTitle:@"Aspect Fit"
  45. viewClass:MASExampleAspectFitView.class],
  46. [[MASExampleViewController alloc] initWithTitle:@"Basic Animated"
  47. viewClass:MASExampleAnimatedView.class],
  48. [[MASExampleViewController alloc] initWithTitle:@"Debugging Helpers"
  49. viewClass:MASExampleDebuggingView.class],
  50. [[MASExampleViewController alloc] initWithTitle:@"Bacony Labels"
  51. viewClass:MASExampleLabelView.class],
  52. [[MASExampleViewController alloc] initWithTitle:@"UIScrollView"
  53. viewClass:MASExampleScrollView.class],
  54. [[MASExampleViewController alloc] initWithTitle:@"Array"
  55. viewClass:MASExampleArrayView.class],
  56. [[MASExampleViewController alloc] initWithTitle:@"Attribute Chaining"
  57. viewClass:MASExampleAttributeChainingView.class],
  58. [[MASExampleViewController alloc] initWithTitle:@"Margins"
  59. viewClass:MASExampleMarginView.class],
  60. ];
  61. if ([UIViewController instancesRespondToSelector:@selector(topLayoutGuide)])
  62. {
  63. self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleLayoutGuideViewController alloc] init]];
  64. }
  65. return self;
  66. }
  67. - (void)viewDidLoad {
  68. [super viewDidLoad];
  69. self.view.backgroundColor = [UIColor whiteColor];
  70. [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
  71. }
  72. #pragma mark - UITableViewDataSource
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  74. UIViewController *viewController = self.exampleControllers[indexPath.row];
  75. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMASCellReuseIdentifier forIndexPath:indexPath];
  76. cell.textLabel.text = viewController.title;
  77. return cell;
  78. }
  79. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  80. return self.exampleControllers.count;
  81. }
  82. #pragma mark - UITableViewDelegate
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  84. UIViewController *viewController = self.exampleControllers[indexPath.row];
  85. [self.navigationController pushViewController:viewController animated:YES];
  86. }
  87. @end