MASExampleListViewController.m
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// MASExampleListViewController.h
// Masonry
//
// Created by Jonas Budelmann on 21/07/13.
// Copyright (c) 2013 cloudling. All rights reserved.
//
#import "MASExampleListViewController.h"
#import "MASExampleViewController.h"
#import "MASExampleBasicView.h"
#import "MASExampleConstantsView.h"
#import "MASExampleSidesView.h"
#import "MASExampleAnimatedView.h"
#import "MASExampleDebuggingView.h"
#import "MASExampleLabelView.h"
#import "MASExampleUpdateView.h"
#import "MASExampleRemakeView.h"
#import "MASExampleScrollView.h"
#import "MASExampleLayoutGuideViewController.h"
#import "MASExampleArrayView.h"
#import "MASExampleAttributeChainingView.h"
#import "MASExampleAspectFitView.h"
#import "MASExampleMarginView.h"
#import "MASExampleDistributeView.h"
static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
@interface MASExampleListViewController ()
@property (nonatomic, strong) NSArray *exampleControllers;
@end
@implementation MASExampleListViewController
- (id)init {
self = [super init];
if (!self) return nil;
self.title = @"Examples";
self.exampleControllers = @[
[[MASExampleViewController alloc] initWithTitle:@"Basic"
viewClass:MASExampleBasicView.class],
[[MASExampleViewController alloc] initWithTitle:@"Update Constraints"
viewClass:MASExampleUpdateView.class],
[[MASExampleViewController alloc] initWithTitle:@"Remake Constraints"
viewClass:MASExampleRemakeView.class],
[[MASExampleViewController alloc] initWithTitle:@"Using Constants"
viewClass:MASExampleConstantsView.class],
[[MASExampleViewController alloc] initWithTitle:@"Composite Edges"
viewClass:MASExampleSidesView.class],
[[MASExampleViewController alloc] initWithTitle:@"Aspect Fit"
viewClass:MASExampleAspectFitView.class],
[[MASExampleViewController alloc] initWithTitle:@"Basic Animated"
viewClass:MASExampleAnimatedView.class],
[[MASExampleViewController alloc] initWithTitle:@"Debugging Helpers"
viewClass:MASExampleDebuggingView.class],
[[MASExampleViewController alloc] initWithTitle:@"Bacony Labels"
viewClass:MASExampleLabelView.class],
[[MASExampleViewController alloc] initWithTitle:@"UIScrollView"
viewClass:MASExampleScrollView.class],
[[MASExampleViewController alloc] initWithTitle:@"Array"
viewClass:MASExampleArrayView.class],
[[MASExampleViewController alloc] initWithTitle:@"Attribute Chaining"
viewClass:MASExampleAttributeChainingView.class],
[[MASExampleViewController alloc] initWithTitle:@"Margins"
viewClass:MASExampleMarginView.class],
[[MASExampleViewController alloc] initWithTitle:@"Views Distribute"
viewClass:MASExampleDistributeView.class],
];
if ([UIViewController instancesRespondToSelector:@selector(topLayoutGuide)])
{
self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleLayoutGuideViewController alloc] init]];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
}
#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *viewController = self.exampleControllers[indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMASCellReuseIdentifier forIndexPath:indexPath];
cell.textLabel.text = viewController.title;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.exampleControllers.count;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *viewController = self.exampleControllers[indexPath.row];
[self.navigationController pushViewController:viewController animated:YES];
}
@end