MASExampleListViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
  18. @interface MASExampleListViewController ()
  19. @property (nonatomic, strong) NSArray *exampleControllers;
  20. @end
  21. @implementation MASExampleListViewController
  22. - (id)init {
  23. self = [super init];
  24. if (!self) return nil;
  25. self.title = @"Examples";
  26. self.exampleControllers = @[
  27. [[MASExampleViewController alloc] initWithTitle:@"Basic"
  28. viewClass:MASExampleBasicView.class],
  29. [[MASExampleViewController alloc] initWithTitle:@"Using Constants"
  30. viewClass:MASExampleConstantsView.class],
  31. [[MASExampleViewController alloc] initWithTitle:@"Composite sides"
  32. viewClass:MASExampleSidesView.class],
  33. [[MASExampleViewController alloc] initWithTitle:@"Basic Animated"
  34. viewClass:MASExampleAnimatedView.class],
  35. [[MASExampleViewController alloc] initWithTitle:@"Debugging helpers"
  36. viewClass:MASExampleDebuggingView.class],
  37. [[MASExampleViewController alloc] initWithTitle:@"Bacony Labels"
  38. viewClass:MASExampleLabelView.class],
  39. [[MASExampleViewController alloc] initWithTitle:@"Update constraints"
  40. viewClass:MASExampleUpdateView.class],
  41. ];
  42. return self;
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
  47. }
  48. #pragma mark - UITableViewDataSource
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  50. UIViewController *viewController = self.exampleControllers[indexPath.row];
  51. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMASCellReuseIdentifier forIndexPath:indexPath];
  52. cell.textLabel.text = viewController.title;
  53. return cell;
  54. }
  55. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  56. return self.exampleControllers.count;
  57. }
  58. #pragma mark - UITableViewDelegate
  59. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  60. UIViewController *viewController = self.exampleControllers[indexPath.row];
  61. [self.navigationController pushViewController:viewController animated:YES];
  62. }
  63. @end