图像缓存问题

时间:2011-08-19 16:25:02

标签: iphone ios

我有一个带有UITableView的iPhone应用程序。我从互联网上下载图像并将它们放在TableViewcell中。首先,我缓存图像,然后将它们加载到TableView中。在第一眼看来,它看起来像图像缓存良好,并在tableview中很好地加载。但是当我滚动TableView时,应用程序崩溃了,我收到一个错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSPathStore2 isFileURL]: unrecognized selector sent to instance 0x6e4d800'

我使用本教程/示例来缓存图像:http://www.makebetterthings.com/blogs/iphone/image-caching-in-iphone-sdk/

有谁知道出了什么问题以及我必须做些什么才能解决这个问题?

谢谢,

耶勒

1 个答案:

答案 0 :(得分:3)

您正在调用NSString上不存在的方法(方法为isFileURL)。该方法存在于NSURL上,所以我猜解决方案是这样的:

// Turn the string into a url
NSString *myPath = @"/cache/image1.png";
NSURL *myURL = [NSURL fileURLWithPath:myPath];

// This line would previously have crashed
BOOL isFile = [myURL isFileURL];

另一种可能性是你认为你正在使用NSURL,但你忘了retain它:)