Skip to content

Commit 1f34a8b

Browse files
committed
Merge pull request jdg#36 from renebigot/master
Bug correction in notification observer + ARC
2 parents f4e551a + bef5e79 commit 1f34a8b

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

MBProgressHUD.h

100644100755
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ typedef enum {
104104

105105
float progress;
106106

107+
#if __has_feature(objc_arc)
108+
id<MBProgressHUDDelegate> __weak delegate;
109+
#else
107110
id<MBProgressHUDDelegate> delegate;
108-
NSString *labelText;
111+
#endif
112+
NSString *labelText;
109113
NSString *detailsLabelText;
110114
float opacity;
111115
UIFont *labelFont;
@@ -165,8 +169,11 @@ typedef enum {
165169
* The UIView (i.g., a UIIMageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
166170
* For best results use a 37 by 37 pixel view (so the bounds match the build in indicator bounds).
167171
*/
172+
#if __has_feature(objc_arc)
173+
@property (strong) UIView *customView;
174+
#else
168175
@property (retain) UIView *customView;
169-
176+
#endif
170177
/**
171178
* MBProgressHUD operation mode. Switches between indeterminate (MBProgressHUDModeIndeterminate) and determinate
172179
* progress (MBProgressHUDModeDeterminate). The default is MBProgressHUDModeIndeterminate.
@@ -187,8 +194,11 @@ typedef enum {
187194
* delegate should conform to the MBProgressHUDDelegate protocol and implement the hudWasHidden method. The delegate
188195
* object will not be retained.
189196
*/
197+
#if __has_feature(objc_arc)
198+
@property (weak) id<MBProgressHUDDelegate> delegate;
199+
#else
190200
@property (assign) id<MBProgressHUDDelegate> delegate;
191-
201+
#endif
192202
/**
193203
* An optional short message to be displayed below the activity indicator. The HUD is automatically resized to fit
194204
* the entire text. If the text is too long it will get clipped by displaying "..." at the end. If left unchanged or
@@ -267,13 +277,19 @@ typedef enum {
267277
/**
268278
* Font to be used for the main label. Set this property if the default is not adequate.
269279
*/
280+
#if __has_feature(objc_arc)
281+
@property (strong) UIFont* labelFont;
282+
#else
270283
@property (retain) UIFont* labelFont;
271-
284+
#endif
272285
/**
273286
* Font to be used for the details label. Set this property if the default is not adequate.
274287
*/
288+
#if __has_feature(objc_arc)
289+
@property (strong) UIFont* detailsLabelFont;
290+
#else
275291
@property (retain) UIFont* detailsLabelFont;
276-
292+
#endif
277293
/**
278294
* The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0.
279295
*/

MBProgressHUD.m

100644100755
Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ - (void)handleGraceTimer:(NSTimer *)theTimer;
1919
- (void)handleMinShowTimer:(NSTimer *)theTimer;
2020
- (void)setTransformForCurrentOrientation:(BOOL)animated;
2121
- (void)cleanUp;
22-
- (void)deviceOrientationDidChange:(NSNotification*)notification;
2322
- (void)launchExecution;
2423
- (void)deviceOrientationDidChange:(NSNotification *)notification;
2524
- (void)hideDelayed:(NSNumber *)animated;
2625
- (void)launchExecution;
2726
- (void)cleanUp;
2827

28+
#if __has_feature(objc_arc)
29+
@property (strong) UIView *indicator;
30+
@property (strong) NSTimer *graceTimer;
31+
@property (strong) NSTimer *minShowTimer;
32+
@property (strong) NSDate *showStarted;
33+
#else
2934
@property (retain) UIView *indicator;
30-
@property (assign) float width;
31-
@property (assign) float height;
3235
@property (retain) NSTimer *graceTimer;
3336
@property (retain) NSTimer *minShowTimer;
3437
@property (retain) NSDate *showStarted;
38+
#endif
39+
40+
@property (assign) float width;
41+
@property (assign) float height;
3542

3643
@end
3744

@@ -149,14 +156,18 @@ - (float)progress {
149156

150157
- (void)updateLabelText:(NSString *)newText {
151158
if (labelText != newText) {
159+
#if !__has_feature(objc_arc)
152160
[labelText release];
161+
#endif
153162
labelText = [newText copy];
154163
}
155164
}
156165

157166
- (void)updateDetailsLabelText:(NSString *)newText {
158167
if (detailsLabelText != newText) {
168+
#if !__has_feature(objc_arc)
159169
[detailsLabelText release];
170+
#endif
160171
detailsLabelText = [newText copy];
161172
}
162173
}
@@ -171,13 +182,22 @@ - (void)updateIndicators {
171182
}
172183

173184
if (mode == MBProgressHUDModeDeterminate) {
185+
#if __has_feature(objc_arc)
186+
self.indicator = [[MBRoundProgressView alloc] init];
187+
#else
174188
self.indicator = [[[MBRoundProgressView alloc] init] autorelease];
175-
}
189+
#endif
190+
}
176191
else if (mode == MBProgressHUDModeCustomView && self.customView != nil){
177192
self.indicator = self.customView;
178193
} else {
194+
#if __has_feature(objc_arc)
195+
self.indicator = [[UIActivityIndicatorView alloc]
196+
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
197+
#else
179198
self.indicator = [[[UIActivityIndicatorView alloc]
180199
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
200+
#endif
181201
[(UIActivityIndicatorView *)indicator startAnimating];
182202
}
183203

@@ -200,7 +220,11 @@ + (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL)animated {
200220
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
201221
[view addSubview:hud];
202222
[hud show:animated];
223+
#if __has_feature(objc_arc)
224+
return hud;
225+
#else
203226
return [hud autorelease];
227+
#endif
204228
}
205229

206230
+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated {
@@ -245,6 +269,15 @@ - (id)initWithView:(UIView *)view {
245269
return me;
246270
}
247271

272+
- (void)removeFromSuperview {
273+
[[NSNotificationCenter defaultCenter] removeObserver:self
274+
name:UIDeviceOrientationDidChangeNotification
275+
object:nil];
276+
277+
[super removeFromSuperview];
278+
}
279+
280+
248281
- (id)initWithFrame:(CGRect)frame {
249282
self = [super initWithFrame:frame];
250283
if (self) {
@@ -287,9 +320,8 @@ - (id)initWithFrame:(CGRect)frame {
287320
return self;
288321
}
289322

323+
#if !__has_feature(objc_arc)
290324
- (void)dealloc {
291-
[[NSNotificationCenter defaultCenter] removeObserver:self];
292-
293325
[indicator release];
294326
[label release];
295327
[detailsLabel release];
@@ -301,6 +333,7 @@ - (void)dealloc {
301333
[customView release];
302334
[super dealloc];
303335
}
336+
#endif
304337

305338
#pragma mark -
306339
#pragma mark Layout
@@ -484,9 +517,14 @@ - (void)handleMinShowTimer:(NSTimer *)theTimer {
484517
- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated {
485518

486519
methodForExecution = method;
520+
#if __has_feature(objc_arc)
521+
targetForExecution = target;
522+
objectForExecution = object;
523+
#else
487524
targetForExecution = [target retain];
488525
objectForExecution = [object retain];
489-
526+
#endif
527+
490528
// Launch execution in new thread
491529
taskInProgress = YES;
492530
[NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil];
@@ -496,16 +534,19 @@ - (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object
496534
}
497535

498536
- (void)launchExecution {
537+
#if !__has_feature(objc_arc)
499538
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
500-
539+
#endif
501540
// Start executing the requested task
502541
[targetForExecution performSelector:methodForExecution withObject:objectForExecution];
503542

504543
// Task completed, update view in main thread (note: view operations should
505544
// be done only in the main thread)
506545
[self performSelectorOnMainThread:@selector(cleanUp) withObject:nil waitUntilDone:NO];
507546

547+
#if !__has_feature(objc_arc)
508548
[pool release];
549+
#endif
509550
}
510551

511552
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void*)context {
@@ -536,8 +577,10 @@ - (void)cleanUp {
536577

537578
self.indicator = nil;
538579

580+
#if !__has_feature(objc_arc)
539581
[targetForExecution release];
540582
[objectForExecution release];
583+
#endif
541584

542585
[self hide:useAnimation];
543586
}

README.mdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
5050
Change-log
5151
==========
5252

53+
**Version 0.41** @ 03.01.12
54+
55+
- Support for ARC.
56+
5357
**Version 0.4** @ 25.07.10
5458

5559
- Different animation modes. Default set to zoom.

0 commit comments

Comments
 (0)