一個簡單的測試應用程序崩潰在Xcode中5.0.2SDWebImage與NSInvalidArgumentException
- 我創建a blank single view app爲iPhone,
- 再添加一個 「male.png」 的形象工程,
- 拖動的UIImageView到故事板
終於將下面的代碼添加到
viewDidLoad
:_imageView.image = [UIImage imageNamed:@"male.png"];
這非常適用:
然後我從SDWebImage project添加文件,改變ViewController.m到:
#import "ViewController.h"
#import <SDWebImage/UIImageView+WebCache.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]
placeholderImage:[UIImage imageNamed:@"male.png"]];
}
@end
不幸的是,這會導致應用程序崩潰與錯誤消息:
2014-01-11 19:21:57.731 sdImage[2563:70b] -[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x8a5aa80
2014-01-11 19:21:57.745 sdImage[2563:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x8a5aa80'
*** First throw call stack:
(
0 CoreFoundation 0x017395e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x017d6903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0172990b ___forwarding___ + 1019
4 CoreFoundation 0x017294ee _CF_forwarding_prep_0 + 14
5 sdImage 0x00002b43 -[ViewController viewDidLoad] + 227
6 UIKit 0x0033e318 -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x0033e5b4 -[UIViewController view] + 35
8 UIKit 0x002669fd -[UIWindow addRootViewControllerViewIfPossible] + 66
9 UIKit 0x00266d97 -[UIWindow _setHidden:forced:] + 312
10 UIKit 0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49
11 UIKit 0x0027189a -[UIWindow makeKeyAndVisible] + 65
12 UIKit 0x00224cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
13 UIKit 0x002293a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
14 UIKit 0x0023d87c -[UIApplication handleEvent:withNewEvent:] + 3447
15 UIKit 0x0023dde9 -[UIApplication sendEvent:] + 85
16 UIKit 0x0022b025 _UIApplicationHandleEvent + 736
17 GraphicsServices 0x036e02f6 _PurpleEventCallback + 776
18 GraphicsServices 0x036dfe01 PurpleEventCallback + 46
19 CoreFoundation 0x016b4d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
20 CoreFoundation 0x016b4a9b __CFRunLoopDoSource1 + 523
21 CoreFoundation 0x016df77c __CFRunLoopRun + 2156
22 CoreFoundation 0x016deac3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x016de8db CFRunLoopRunInMode + 123
24 UIKit 0x00228add -[UIApplication _run] + 840
25 UIKit 0x0022ad3b UIApplicationMain + 1225
26 sdImage 0x00002ffd main + 141
27 libdyld.dylib 0x01d7770d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
爲什麼會發生這種情況?在添加框架文件時,我已經設置複選框來複制文件。
UPDATE:
我也曾嘗試以下操作:
git submodule add https://github.com/rs/SDWebImage.git
然後建立了一個項目(SDWebImage.xcodeproj),並關閉它。
然後我在Xcode我的項目(sdImage.xcodeproj)中重新打開並將SDWebImage.xcodeproj文件拖入其中。
之後,我已經嘗試添加目標依賴,但它並不顯示一個名爲「SDWebImage」有什麼:
而且我無法在鏈接二進制文件庫下添加「SDWebImage.framework」,因爲沒有名爲「SDWebImage」的文件。
嘗試在構建設置中將以下內容添加到「其他鏈接器標誌」:「-force_load $ { BUILT_PRODUCTS_DIR} /libSDWebImageARC.a「 – 7c9d6b001a87e497d6b96fbd4c6fdf
當我從https://github.com/rs/SDWebImage/releases下載任何zip壓縮文檔時,那裏沒有'libSDWebImageARC.a'文件。只有幾個標題和一個「SDWebImage」文件。 –
我不明白你的問題是什麼。 github中的項目工作正常,並加載你的avtar – Johnykutty