嘿,我是iPhone新手,我一直试图在离线模式下在桌面视图单元格上显示图像图标。
使用NSUserDefault
我在线模式下本地存储数组对象。我正在使用创建NSURLRequest
的方法,并使用NSURLConnection
方法sendAsynchronousRequest:queue:completionHandler
发送该请求:有时候我没有使用这种方法得到任何响应,所以completionHandler没有调用。所以我没有在桌子上得到任何图像图标。有谁知道如何解决这个问题?
这是我的代码:
QuickLinksTab *quickLinksmenu = [[QuickLinksTab alloc] init];
quickLinksmenu = [arrayLinks objectAtIndex:indexPath.row];
cell.lblName.text = quickLinksmenu.title;
NSString *strQuickLink = [NSString stringWithFormat:@"http://%@",quickLinksmenu.iconImage];
NSURL* url = [NSURL URLWithString:strQuickLink];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (error)
{
NSLog(@"ERROR CONNECTING DATA FROM SERVER: %@", error.localizedDescription);
}
else{
UIImage* image = [[UIImage alloc] initWithData:data];
// do whatever you want with image
if (image) {
cell.imageIcon.image = image;
}
else{
cell.imageIcon.image = [UIImage imageNamed:@"DefaultPlace.png"];
}
}
}];
QuickLinksTab是我的实体类,我在我的应用程序中本地存储quickLinksmenu.title
和quickLinksmenu.iconImage
。我收到错误信息 - “
错误从服务器连接数据:
互联网连接似乎处于离线状态。
先谢谢。