【发布时间】:2013-08-07 06:09:21
【问题描述】:
我有一个UITabBarController,其中 UITableViewControllerA 列出文件,UITableViewContollerB 显示正在上传的文件的进度。
我有一个单例类,其上传方法调用我的子类AFHTTPClient 并使用NSNotificationCenter 通知我的 UITableViewControllerB 上传进度。但是这种当前的方式正在将 UI 减慢到几乎无法使用的程度,我不确定如何改进这个过程。我读到 AFNetworking 回调函数是在主线程上调用的。缓慢的 UI 响应是否来自我的 NSNotificationCenter?
我还想提一下我正在模拟器上运行它。
我的 Singleton 类中的方法。
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:uniqueName forKey:@"unique"];
[dict setObject:[NSNumber numberWithFloat:0] forKey:@"progress"];
[self.active addObject:dict];
[[CustomHTTP client] uploadFileName:@"filename" withBytes:data toPath:serverPath progress:^(float progress) {
[dict setObject:progress forKey:@"progress"];
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:[NSNumber numberWithInt:[self getIndexByUniquename:uniqueName]] forKey:@"row"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ProgressNotification" object:self userInfo:info];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} andFailure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
UITableViewControllerB.m
- (void) receiveTestNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"ProgressNotification"]) {
NSDictionary *dict = notification.userInfo;
int row = [[dict objectForKey:@"row"] intValue];
self.inProgress = [Transfer defaultTransfer].active;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
}
【问题讨论】:
-
您同时运行多少次上传?使用仪器查看正在发生的事情。
-
@Wain 我正在运行 2 次上传 30MB+。我应该使用哪种仪器?
-
使用范围,检查处理器使用情况(时间分析)和内存使用情况。同时上传2个应该没问题。您获得了多少进度更新。
-
@Wain 获取我的 34MB 文件,8300 个进度更新。
-
仅在特定时间段进行更新,例如每 0.2 秒更新一次 UI 应该没问题、流畅且仍能响应
标签: iphone ios afnetworking