Browse Source

Ensuring that start and stop animating for UIActivityIndicatorView category are called on main

Mattt Thompson 12 years ago
parent
commit
afffa6ff52
1 changed files with 19 additions and 5 deletions
  1. 19 5
      UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m

+ 19 - 5
UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m

@@ -40,8 +40,8 @@
             [self stopAnimating];
         }
 
-        [notificationCenter addObserver:self selector:@selector(startAnimating) name:AFNetworkingOperationDidStartNotification object:operation];
-        [notificationCenter addObserver:self selector:@selector(stopAnimating) name:AFNetworkingOperationDidFinishNotification object:operation];
+        [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingOperationDidStartNotification object:operation];
+        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingOperationDidFinishNotification object:operation];
     }
 }
 
@@ -59,10 +59,24 @@
             [self stopAnimating];
         }
 
-        [notificationCenter addObserver:self selector:@selector(startAnimating) name:AFNetworkingTaskDidStartNotification object:task];
-        [notificationCenter addObserver:self selector:@selector(stopAnimating) name:AFNetworkingTaskDidFinishNotification object:task];
-        [notificationCenter addObserver:self selector:@selector(stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
+        [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidStartNotification object:task];
+        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidFinishNotification object:task];
+        [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
     }
 }
 
+#pragma mark -
+
+- (void)af_startAnimating {
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        [self startAnimating];
+    });
+}
+
+- (void)af_stopAnimating {
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        [self stopAnimating];
+    });
+}
+
 @end