forked from facebookarchive/three20
/
TTAlertViewController.m
101 lines (76 loc) · 2.76 KB
/
TTAlertViewController.m
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
#import "Three20/TTAlertViewController.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface TTAlertView : UIAlertView {
UIViewController* _popupViewController;
}
@property(nonatomic,retain) UIViewController* popupViewController;
@end
@implementation TTAlertView
@synthesize popupViewController = _popupViewController;
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_popupViewController = nil;
}
return self;
}
- (void)dealloc {
[super dealloc];
}
- (void)didMoveToSuperview {
if (!self.superview) {
[_popupViewController release];
}
}
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTAlertViewController
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)initWithTitle:(NSString*)title message:(NSString*)message delegate:(id)delegate
cancelButtonTitle:(NSString*)cancelButtonTitle
otherButtonTitles:(NSString*)otherButtonTitles, ... {
if (self = [super init]) {
TTAlertView* alertView = [[[TTAlertView alloc] initWithTitle:title message:message
delegate:delegate
cancelButtonTitle:cancelButtonTitle
otherButtonTitles:nil] autorelease];
alertView.popupViewController = self;
va_list ap;
va_start(ap, otherButtonTitles);
while (otherButtonTitles) {
[alertView addButtonWithTitle:otherButtonTitles];
otherButtonTitles = va_arg(ap, id);
}
va_end(ap);
self.view = alertView;
}
return self;
}
- (void)dealloc {
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController
- (void)loadView {
TTAlertView* alertView = [[[TTAlertView alloc] init] autorelease];
alertView.popupViewController = self;
self.view = alertView;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTPopupViewController
- (void)showInViewController:(UIViewController*)parentViewController animated:(BOOL)animated {
[self viewWillAppear:animated];
[self.alertView show];
[self viewDidAppear:animated];
}
- (void)dismissPopupViewControllerAnimated:(BOOL)animated {
[self viewWillDisappear:animated];
[self.alertView dismissWithClickedButtonIndex:self.alertView.cancelButtonIndex animated:animated];
[self viewDidDisappear:animated];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// public
- (UIAlertView*)alertView {
return (UIAlertView*)self.view;
}
@end