-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathSimpleSplitController.m
More file actions
88 lines (68 loc) · 3.09 KB
/
SimpleSplitController.m
File metadata and controls
88 lines (68 loc) · 3.09 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
//
// ConcreteSplitController1.m
// SplitSample
//
// Created by slatvick on 3/12/11.
// Copyright 2011 Alterplay. All rights reserved.
//
#import "SimpleSplitController.h"
@interface SimpleSplitController()
- (UIColor *) randomColor;
- (UIViewController*) randomViewController1;
- (UIViewController*) randomViewController2;
- (void) buttonPushRandomViewController1;
- (void) buttonPushRandomViewController2;
@end
@implementation SimpleSplitController
@synthesize left, right;
#pragma mark - View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.left = [self randomViewController1];
self.right = [self randomViewController2];
[self pushToMasterController:self.left];
[self pushToDetailController:self.right];
self.left.title = @"Left root";
self.right.title = @"Right root";
}
- (void)viewDidUnload {
[super viewDidUnload];
self.left = nil;
self.right = nil;
}
#pragma mark - Helpers
- (UIColor *) randomColor {
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;
return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}
- (UIViewController*) randomViewController1 {
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [self randomColor];
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(buttonPushRandomViewController1)];
return viewController;
}
- (UIViewController*) randomViewController2 {
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [self randomColor];
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(buttonPushRandomViewController2)];
return viewController;
}
- (void) buttonPushRandomViewController1 {
UIViewController *randomViewController = [self randomViewController1];
randomViewController.title = @"First";
[self.master pushViewController:randomViewController animated:YES];
}
- (void) buttonPushRandomViewController2 {
UIViewController *randomViewController = [self randomViewController2];
randomViewController.title = @"Second";
[self.detail pushViewController:randomViewController animated:YES];
}
@end