SDWebImage : setImageWithURL fails when used to se

2020-05-23 03:42发布

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"]];    

13条回答
我命由我不由天
2楼-- · 2020-05-23 04:22

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.

查看更多
我命由我不由天
3楼-- · 2020-05-23 04:22

Solved the same problem adding the libSDWebImage.a to Build Phases > Link Binary with Libraries.

查看更多
男人必须洒脱
4楼-- · 2020-05-23 04:24

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)

  1. Go to build settings > Architecture

  2. Under Architecture, select Standard architectures (armv7,armv7s)

  3. Under Build Active Architecture Only, make sure it is Yes for both Debug and Release

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 =)

查看更多
Rolldiameter
5楼-- · 2020-05-23 04:27

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.

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2020-05-23 04:30

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.

查看更多
爷、活的狠高调
7楼-- · 2020-05-23 04:30

Checkout your choice when you pull files of SDWebimages into Xcode, do mark the "create groups" in added folders, and do not mark the "create folder references".

Mark exactly as the picture:

enter image description here

查看更多
登录 后发表回答