MASExampleListViewController.m 4.2 KB

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