SDWebImage : setImageWithURL fails when used to set image of a UITableViewCell
-
15-04-2021 - |
문제
When call setImageWithURL, it fails with following,
[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x149a20 2011-12-14 18:11:38.060 [781:707] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x149a20'
I can confirm I have included SDWebImage
project and required headers correctly as I can use the SDWebImageManager successfully.
Following is the code where I called the UIImageView category method setImageWithURL
NSURL* url = [NSURL URLWithString:@"www.abc.com/abc.png"];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"abc.png"]];
해결책
I ended up inserting all the .h and .m files into my project and then it worked fine. I got the same error when I only included the .a and .h files.
다른 팁
As per: linking objective-c categories in a static library
Due to a linker bug in XCode, you need to set the 'Other Linker Flags' setting your build target. Setting the flag as follows should eliminate this error.
-force_load ${BUILT_PRODUCTS_DIR}/libSDWebImage.a
This will solve the problem: Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:
If anyone, like me, still has problems after seeing all the other answers here (e.g. force_load or load_all) even after following all the proper installation instructions, here is what I have learnt after doing some search online:
- This problem only happens when you use iPhone 5S or the 64-bit simulator
- This is a problem with libwebp
The solution to this problem: Only do this if you don't need the 64-bit processor for your app (too new to iOS programming to know if this sentence is valid)
Go to build settings > Architecture
Under Architecture, select
Standard architectures (armv7,armv7s)
Under Build Active Architecture Only, make sure it is Yes for both
Debug
andRelease
My source: https://github.com/rs/SDWebImage/issues/494
I hope this helps those who, like me, found this while trying to solve your problem =)
In the SDWebImage docs, it says that you have to set "Other Linker Flags" to -ObjC. This did not work for me. Instead, I set it to -all_load. I also had to remove -ObjC. The explanation for what is going on can be found here:
http://developer.apple.com/library/mac/#qa/qa1490/_index.html
It also explains why -ObjC fails: "Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the f-all_load or -force_load flags"
Using -all_load increases the size of the executable. You can use -force_load to mitigate this somewhat. For SDWebImage 2.7.3, I did this by setting the following in "Other Linker Flags" in the Build Settings: "-load_all $(SRCROOT)/SDWebImage.framework/SDWebImage". Linking to libSDWebImage[ARC].a which is what some sources advise, didn't work for me.
Incidentally, in Xcode 4.4, it seems you have to do a slow double-click in order to change build settings properly. Doing a normal double-click shows the completely screwed up and non-working pop-up.
Solved the same problem adding the libSDWebImage.a to Build Phases > Link Binary with Libraries.
If you read the document here https://github.com/rs/SDWebImage at the bottom there is a download link with the CORRECT files to download. Following that example it works perfectly.
The mistake I made, and seemingly others to, is I downloaded the github project and tried using that.
Everything started to work for me once I linked "ImageIO.framework" to my main project.
You can also set 'Other Linker Flags' to -all_load. This solves the problem where an external framework (such as the filepicker framework) requires linking against SDWebImage.
-force_load is not fix fundamental problem (when achiveing problem happens) to fix this linking problem..
- edit scheme for SDWebImage,
- run scheme set for release
- run (with device)
- libSDWebImage.a will be generated in release-iphoneos directory.
- set target->BuildPhase->link Binarywithlibrary .. add this lib.
- Done..
Make sure your compiled files have UIIMageView+AFNetworking.m in case you're using AFNetworking framework.
You need to add the libSDWebImage.a in your linked binaries, also check for other linker flags, it should be -ObjC