在互联网上搜索了数周并且堆栈中也有很多帖子之后,我似乎找不到在我的项目中实现这一点的方法。
我的 Dropbox 帐户中有一个 plist。在名为“cellPic”的字典之一下的 plist 中的字符串之一。
我想在表格单元格上显示我在我的保管箱中拥有的商店的图片。
plist 已下载到我的文档路径:
-(void)readPlistFromServerAndSaveToDocs
{
//save plist from server to docs:
NSArray *tempArr1 = [[NSArray alloc]initWithContentsOfURL:
[NSURL URLWithString:@"http://dl.dropbox.com/u/4082823/AppsFiles/Black/stores.plist"]];
NSString *error;
NSString *rootPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"stores.plist"];
NSArray *tmpArr = [NSArray arrayWithArray:tempArr1];
NSData *tmpData = [NSPropertyListSerialization dataFromPropertyList:tmpArr
format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
NSLog(@"plistPath=%@",plistPath);
if(tmpData)
{
[tmpData writeToFile:plistPath atomically:YES];
}
else
{
NSLog(@"%@",error);
}
//Announcement if there is no server connection:
if(tempArr1.count == 0)
{
[self plistMessages];
}
}
到目前为止一切正常...
在此方法下的 TableViewController 中,我想为单元格实现异步图像加载。
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我的目标是异步读取/下载图像,但我不知道它是如何进行的 - 我需要在我的文档路径上读取我的 plist 中包含图片完整 url 地址的字符串还是我需要下载图片从服务器到我的文档,然后将其读取到单元格中?
在我的情况下 - 单元格的位置正在改变 cau,它们按用户位置排序(离用户最近的商店位于表格顶部),这就是为什么我认为我需要从我的 plist 中读取它的原因。
这是我的图片网址之一:http
://dl.dropbox.com/u/4082823/AppsFiles/Black/ramat-hasharon.png
最好的方法是什么以及如何一次下载所有 png 图像(如果需要的话)?
我已经尝试使用本教程来完成它,但它根本没有成功。
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
帮助将被appriciated!
谢谢!