@@ -46,111 +46,80 @@ - (void)dealloc {
46
46
- (IBAction )showSimple : (id )sender {
47
47
// The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
48
48
HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
49
-
50
- // HUD.graceTime = 0.5;
51
- // HUD.minShowTime = 5.0;
52
-
53
- // Add HUD to screen
54
49
[self .navigationController.view addSubview: HUD];
55
50
56
- // Regisete for HUD callbacks so we can remove it from the window at the right time
51
+ // Regiser for HUD callbacks so we can remove it from the window at the right time
57
52
HUD.delegate = self;
58
53
59
54
// Show the HUD while the provided method executes in a new thread
60
55
[HUD showWhileExecuting: @selector (myTask ) onTarget: self withObject: nil animated: YES ];
61
56
}
62
57
63
58
- (IBAction )showWithLabel : (id )sender {
64
- // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
59
+
65
60
HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
61
+ [self .navigationController.view addSubview: HUD];
66
62
67
- // Add HUD to screen
68
- [self .navigationController.view addSubview: HUD];
69
-
70
- // Regisete for HUD callbacks so we can remove it from the window at the right time
71
63
HUD.delegate = self;
72
-
73
64
HUD.labelText = @" Loading" ;
74
65
75
- // Show the HUD while the provided method executes in a new thread
76
66
[HUD showWhileExecuting: @selector (myTask ) onTarget: self withObject: nil animated: YES ];
77
67
}
78
68
79
69
- (IBAction )showWithDetailsLabel : (id )sender {
80
- // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
81
- HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
82
70
83
- // Add HUD to screen
71
+ HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
84
72
[self .navigationController.view addSubview: HUD];
85
73
86
- // Regisete for HUD callbacks so we can remove it from the window at the right time
87
74
HUD.delegate = self;
88
-
89
75
HUD.labelText = @" Loading" ;
90
76
HUD.detailsLabelText = @" updating data" ;
91
77
92
- // Show the HUD while the provided method executes in a new thread
93
78
[HUD showWhileExecuting: @selector (myTask ) onTarget: self withObject: nil animated: YES ];
94
79
}
95
80
96
81
- (IBAction )showWithLabelDeterminate : (id )sender {
97
- // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
82
+
98
83
HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
84
+ [self .navigationController.view addSubview: HUD];
99
85
100
86
// Set determinate mode
101
87
HUD.mode = MBProgressHUDModeDeterminate;
102
-
103
- // Add HUD to screen
104
- [self .navigationController.view addSubview: HUD];
105
-
106
- // Regisete for HUD callbacks so we can remove it from the window at the right time
107
- HUD.delegate = self;
108
-
88
+
89
+ HUD.delegate = self;
109
90
HUD.labelText = @" Loading" ;
110
91
111
- // Show the HUD while the provided method executes in a new thread
92
+ // myProgressTask uses the HUD instance to update progress
112
93
[HUD showWhileExecuting: @selector (myProgressTask ) onTarget: self withObject: nil animated: YES ];
113
94
}
114
95
115
96
- (IBAction )showWithCustomView : (id )sender {
116
- // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
97
+
117
98
HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
99
+ [self .navigationController.view addSubview: HUD];
118
100
119
- // The sample image is based on the work by www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
101
+ // The sample image is based on the work by http:// www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
120
102
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
121
103
HUD.customView = [[[UIImageView alloc ] initWithImage: [UIImage imageNamed: @" 37x-Checkmark.png" ]] autorelease ];
122
104
123
105
// Set custom view mode
124
106
HUD.mode = MBProgressHUDModeCustomView;
125
107
126
- // Add HUD to screen
127
- [self .navigationController.view addSubview: HUD];
128
-
129
- // Regisete for HUD callbacks so we can remove it from the window at the right time
130
108
HUD.delegate = self;
131
-
132
109
HUD.labelText = @" Completed" ;
133
110
134
- // This would only show the completed text with no visible custom view
135
- // HUD.customView = [[UIView alloc] initWithFrame:CGRectZero];
136
-
137
- // Show the HUD while the provided method executes in a new thread
138
- [HUD showWhileExecuting: @selector (myProgressTask ) onTarget: self withObject: nil animated: YES ];
111
+ [HUD show: YES ];
112
+ [HUD hide: YES afterDelay: 3 ];
139
113
}
140
114
141
115
- (IBAction )showWithLabelMixed : (id )sender {
142
- // The hud will dispable all input on the view (use the higest view possible in the view hierarchy)
116
+
143
117
HUD = [[MBProgressHUD alloc ] initWithView: self .navigationController.view];
118
+ [self .navigationController.view addSubview: HUD];
144
119
145
- // Add HUD to screen
146
- [self .navigationController.view addSubview: HUD];
147
-
148
- // Regisete for HUD callbacks so we can remove it from the window at the right time
149
120
HUD.delegate = self;
150
-
151
121
HUD.labelText = @" Connecting" ;
152
122
153
- // Show the HUD while the provided method executes in a new thread
154
123
[HUD showWhileExecuting: @selector (myMixedTask ) onTarget: self withObject: nil animated: YES ];
155
124
}
156
125
@@ -161,12 +130,8 @@ - (IBAction)showUsingBlocks:(id)sender {
161
130
hud.labelText = @" Loading" ;
162
131
163
132
dispatch_async (dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_LOW, 0 ), ^{
164
-
165
133
// Do a taks in the background
166
134
[self myTask ];
167
- hud.labelText = @" Some more" ;
168
- [self myTask ];
169
-
170
135
// Hide the HUD in the main tread
171
136
dispatch_async (dispatch_get_main_queue (), ^{
172
137
[MBProgressHUD hideHUDForView: self .navigationController.view animated: YES ];
@@ -176,18 +141,13 @@ - (IBAction)showUsingBlocks:(id)sender {
176
141
}
177
142
178
143
- (IBAction )showOnWindow : (id )sender {
179
- // The hud will dispable all input on the view
144
+ // The hud will dispable all input on the window
180
145
HUD = [[MBProgressHUD alloc ] initWithView: self .view.window];
181
-
182
- // Add HUD to screen
183
146
[self .view.window addSubview: HUD];
184
147
185
- // Regisete for HUD callbacks so we can remove it from the window at the right time
186
148
HUD.delegate = self;
187
-
188
149
HUD.labelText = @" Loading" ;
189
150
190
- // Show the HUD while the provided method executes in a new thread
191
151
[HUD showWhileExecuting: @selector (myTask ) onTarget: self withObject: nil animated: YES ];
192
152
}
193
153
@@ -241,6 +201,7 @@ - (void)hudWasHidden {
241
201
// Remove HUD from screen when the HUD was hidded
242
202
[HUD removeFromSuperview ];
243
203
[HUD release ];
204
+ HUD = nil ;
244
205
}
245
206
246
207
@end
0 commit comments