MASExampleListViewController.m 4.6 KB

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