فهرست منبع

1.修改iOS Apex Drivers上传列表在UploadManager之前初始化,界面刷新会导致数组越界。

Pen Li 7 سال پیش
والد
کامیت
29708ab250
1فایلهای تغییر یافته به همراه13 افزوده شده و 6 حذف شده
  1. 13 6
      common/upload/RAUploadListViewController.m

+ 13 - 6
common/upload/RAUploadListViewController.m

@@ -24,11 +24,16 @@
     
     AppDelegate* appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
     
-    
-    [appdelegate.uploadManager addObserver:self
-                                forKeyPath:@"arr_queue"
-                                   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
-                                   context:@"arr_queue changed"];
+    // 如果ViewController创建在UploadManager初始化之前,那么KVO失效,界面刷新不正确而导致数组越界
+    if (appdelegate.uploadManager != nil) {
+        [appdelegate.uploadManager addObserver:self
+                                    forKeyPath:@"arr_queue"
+                                       options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
+                                       context:@"arr_queue changed"];
+    } else {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadRefreshNotification:) name:UPLOAD_COUNT_CHANGE_NOTIFICATION object:nil];
+        
+    }
     
     self.title = NSLocalizedString(@"Upload List", nil);
     UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Clear", nil) style:UIBarButtonItemStylePlain target:self action:@selector(clearList)];
@@ -96,7 +101,9 @@
 }
 
 - (void)uploadRefreshNotification:(NSNotification *)notification {
-    [self.uploadTableView reloadData];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [self.uploadTableView reloadData];
+    });
 }
 
 #pragma mark - TableView DataSource