我现在正在开发一个 iOS 应用程序
我有一个包含一些用户数据的网络服务。
一旦我使用 URLRequest 获取数据,它就很顺利,我真的从服务器获得了我想要的数据量。
theRequest = [[NSMutableURLRequest alloc]
initWithURL: [NSURL URLWithString:URL]
cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval: 10
];
/////////////////
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data", [receivedData length]);
switch (getType) {
case 0:
default:
[delegate performSelectorOnMainThread:@selector(didFinishDownloadLoad:) withObject:receivedData waitUntilDone:false];
但问题是,我需要将数据提取到 uitableviecell。
如果我包含 10 个数据列表,我需要循环 10 次来初始化数据。
它将“冻结”我的应用程序,当我获取数据时我无能为力
我应该怎么做才能“不冻结”我的应用程序?
////更新**
-(void) didFinishDownloadLoad:(NSMutableData*)receivedData{
NSData *theData = [[NSData alloc] initWithData:receivedData];
NSError *theError = nil;
NSMutableArray *tmparray = [NSMutableArray array];
NSDictionary *theObject = [NSJSONSerialization JSONObjectWithData:theData options:NSJSONReadingAllowFragments error:&theError];
NSLog(@"theObject:%@",theObject);
NSDictionary *theList = [theObject objectForKey:@"list"];
for (NSString *s in theList)
{
NSDictionary *theNewFeed = [theList objectForKey:s];
NewFeedDetailsManager *newFeedDetails = [[NewFeedDetailsManager alloc] init];
[newFeedDetails setCid:s];
[newFeedDetails setFbid:[theNewFeed objectForKey:@"fbid"]];
[newFeedDetails setFbUserName:[theNewFeed objectForKey:@"fbname"]];
[newFeedDetails setUserComment:[theNewFeed objectForKey:@"comment"]];
[newFeedDetails setRestaurantName:[theNewFeed objectForKey:@"name"]];
[newFeedDetails setRestaurantAddress:[theNewFeed objectForKey:@"address"]];
[newFeedDetails setWriteDate:[theNewFeed objectForKey:@"date"]];
[newFeedDetails setSid:[theNewFeed objectForKey:@"sid"]];
//get User Pro Pic
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", newFeedDetails.fbid]];
newFeedDetails.userimage = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
[tmparray addObject:newFeedDetails];
}
}
谢谢大家,现在我得到了问题..
它冻结在“获取用户个人资料图片”中 NSURL 方法需要花时间来获取图片......所以它会冻结我的应用程序
那么,我应该怎么做才能获取个人资料图片而不是冻结我的应用程序?