【发布时间】:2014-01-30 17:15:45
【问题描述】:
在 Xcode 5.0.2 中
- 我为 iPhone 创建了a blank single view app,
- 然后将“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)
请问为什么会这样?添加框架文件时,我设置了复选框以复制文件。
更新:
我还尝试了以下方法:
git submodule add https://github.com/rs/SDWebImage.git
然后构建该项目 (SDWebImage.xcodeproj) 并关闭它。
然后我在 Xcode 中重新打开了我的项目 (sdImage.xcodeproj) 并将 SDWebImage.xcodeproj 文件拖入其中。
之后我尝试添加目标依赖项,但它没有显示任何名为“SDWebImage”的内容:
我无法在 Link Binary With Libraries 下添加“SDWebImage.framework”,因为那里没有名为“SDWebImage”的内容。
【问题讨论】:
-
尝试将以下内容添加到构建设置中的“其他链接器标志”中:“-force_load ${BUILT_PRODUCTS_DIR}/libSDWebImageARC.a”
-
当我从 github.com/rs/SDWebImage/releases 下载任何 zip 档案时,那里没有
libSDWebImageARC.a文件。只有几个标题和一个SDWebImage文件。 -
我不明白你的问题是什么。 github 中的项目运行良好并在其中加载您的 avtar
-
+1 用于查看我的项目。现在可以(从几分钟开始),因为我终于想出了如何在 CocoaPods 的帮助下将 SDWebImage.framework 集成到我的项目中 - 请在下面查看我自己的答案。
标签: ios iphone objective-c ipad uiimageview