浏览代码

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

Mattt Thompson 12 年之前
父节点
当前提交
afffa6ff52
共有 1 个文件被更改,包括 19 次插入5 次删除
  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