forked from PureLayout/PureLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALiOSDemoListController.m
More file actions
82 lines (68 loc) · 2.63 KB
/
Copy pathALiOSDemoListController.m
File metadata and controls
82 lines (68 loc) · 2.63 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
//
// ALiOSDemoListController.m
// PureLayout Example-iOS
//
// Copyright (c) 2014 Tyler Fox
// https://github.com/smileyborg/PureLayout
//
#import "ALiOSDemoListController.h"
#import "ALiOSDemo1ViewController.h"
#import "ALiOSDemo2ViewController.h"
#import "ALiOSDemo3ViewController.h"
@interface ALiOSDemoListController ()
@property (nonatomic, readonly) NSArray *demoTitles;
@end
@implementation ALiOSDemoListController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"PureLayout iOS Demos";
}
- (NSArray *)demoTitles
{
return @[
@"Basic Auto Layout", // Demo 1
@"Working with Arrays of Views", // Demo 2
@"Distributing Views", // Demo 3
@"Leading & Trailing Attributes", // Demo 4
@"Cross-Attribute Constraints", // Demo 5
@"Priorities & Inequalities", // Demo 6
@"Animating Constraints", // Demo 7
@"Constraint Identifiers (iOS 7.0+)", // Demo 8
@"Layout Margins (iOS 8.0+)" // Demo 9
];
}
- (NSString *)textForDemoAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = self.demoTitles[indexPath.row];
text = [NSString stringWithFormat:@"%@. %@", @(indexPath.row + 1), text];
return text;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.demoTitles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil]; // not bothering to reuse cells here
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [self textForDemoAtIndexPath:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *viewControllerClassName = [NSString stringWithFormat:@"ALiOSDemo%@ViewController", @(indexPath.row + 1)];
Class viewControllerKlass = NSClassFromString(viewControllerClassName);
NSAssert(viewControllerKlass, @"Class should not be nil!");
NSAssert([viewControllerKlass isSubclassOfClass:[UIViewController class]], @"Class should be a view controller!");
UIViewController *demoViewController = [[viewControllerKlass alloc] initWithNibName:nil bundle:nil];
if (demoViewController) {
demoViewController.title = [self textForDemoAtIndexPath:indexPath];
[self.navigationController pushViewController:demoViewController animated:YES];
}
}
@end