一个简单的测试应用程序中的JMImageCache与EXC_BAD_ACCESS崩溃 [英] JMImageCache in a simple test app crashes with EXC_BAD_ACCESS
问题描述
在Xcode 5.0.2中
- 我创建并更改 Jake Marsh(JMImageCache的作者) )注意:
JMImageCache有目的地使用NSString对象而不是NSURL来简化和减少[NSURL URLWithString:@... 比特到处都是。如果您发现任何奇怪的EXC_BAD_ACCESS异常,请注意以下事项,确保您传入NSString而不是NSURL。
但是(作为一个iOS编程新手)我不明白,Marsh先生究竟是什么意思 - 因为他的文件 UIImageView + JMImageCache.m 将公共方法的第一个参数声明为
NSURL
:- (void)setImageWithURL:(NSURL *)url占位符:(UIImage *)占位符图像{
[self setImageWithURL:url key: nil placeholder:placeholderImage];
}
笔记可能已过时,我该如何修复我的应用程序?
解决方案这是JMImageCache中的一个错误。
setImageWithURL:key :占位符:completionBlock:
调用自身,耗尽堆栈。
要解决此问题,请调用较长的形式方法:
[_ imageView setImageWithURL:[NSURL URLWithString:kAvatar]
key:nil
占位符:[ UIImage imageNamed:@male.png]
completionBlock:nil
failureBlock:nil];
或者,使用旧版本的库(例如 0.4.0 )。看起来这个bug是在 1af09be78a 中引入的。
In Xcode 5.0.2
- I create a blank single view app for iPhone,
- then add a "male.png" image to the project,
- drag a UIImageView to the storyboard
and finally add the following code to the
viewDidLoad
:_imageView.image = [UIImage imageNamed:@"male.png"];
This works well:
Then I add the 4 files from JMImageCache project and change the ViewController.m to:
#import "ViewController.h" #import "JMImageCache.h" static NSString* const kAvatar = @"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png"; @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [_imageView setImageWithURL:[NSURL URLWithString:kAvatar] placeholder:[UIImage imageNamed:@"male.png"]]; } @end
Unfortunately, this results in app crash with the error message
Thread 1: EXC_BAD_ACCESS
:At his webpage Jake Marsh (the author of JMImageCache) notes:
JMImageCache purposefully uses NSString objects instead of NSURL's to make things easier and cut down on [NSURL URLWithString:@"..."] bits everywhere. Just something to notice in case you see any strange EXC_BAD_ACCESS exceptions, make sure you're passing in NSString's and not NSURL's.
But (as an iOS programming newbie) I don't understand, what exactly does Mr. Marsh mean - since his file UIImageView+JMImageCache.m declares the 1st argument for the public method as
NSURL
:- (void) setImageWithURL:(NSURL *)url placeholder:(UIImage *)placeholderImage { [self setImageWithURL:url key:nil placeholder:placeholderImage]; }
Is the note maybe outdated and how could I fix my app?
解决方案That's a bug in JMImageCache.
setImageWithURL:key:placeholder:completionBlock:
calls itself, exhausting the stack.To work around the bug, call the longer form of the method:
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar] key:nil placeholder:[UIImage imageNamed:@"male.png"] completionBlock:nil failureBlock:nil];
Or, use an older version of the library (e.g. 0.4.0). Looks like the bug was introduced in 1af09be78a.
这篇关于一个简单的测试应用程序中的JMImageCache与EXC_BAD_ACCESS崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!