MASExampleListViewController.m 4.9 KB

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