在搜索了几周的网络之后&很多帖子都在这里,我似乎无法找到在我的项目中实现此功能的方式。
我在我的保管箱帐户中有一个plist。其中一个名为“cellPic”的字典中的字符串之一。
我想在我的保管箱中的表格单元格上显示商店的照片。这个方法我想实现异步加载图像在细胞下将图像异步加载到tableview单元格中
-(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:
plist中被下载到我的文档路径。
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我的目标是读/异步下载图像,但我不知道如何去 - 我需要阅读我的plist中的字符串包含PIC的完整URL地址我的文档路径或者我需要从服务器下载图片到我的文档&然后将其读取到单元格?
在我的情况 - 细胞possitions正在改变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!
谢谢!
感谢lawicko,我之前看过它,但它看起来像有很多代码和子类来实现。我确信有一个简短的方法可以做到这一点从我在网上看到的代码,但我都很困惑,不知道该怎么做:/ – 2012-02-27 17:38:08
认真?这里只有两个应该感兴趣的类,'IconDownloader'和'RootViewController'。如果你发现比这更简单的例子,我会买啤酒。 – lawicko 2012-02-27 18:02:08
:)哦,我想我需要他们所有人!对不起,我会尽力让它与这个例子一起工作..对不起,我是新的xcode ...如果它的工作 - 我会给你买一杯啤酒;) – 2012-02-27 18:07:50