Solve Error: 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'


 

下面是iOS開發用第三方庫可能出現的錯誤,及其解決方法:

1. 'NSInvalidArgumentException', reason: '-[UITableView mas_makeConstraints:]: unrecognized selector sent to instance 0x7fa5c402fa00'

這個是使用Masonry庫時遇到的,Masonry庫是做Auto Layout的神器,封裝的特別好,用幾行代碼就可以實現非常復雜的自動排布功能。這個錯誤的產生原因可能是因為直接將第三方庫拖入項目中,那么還是需要設置target membership,解決方法如下:

- Choose every *.m file, go to File Inspector

- Go to Target Membership, check your app target.

 

2. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView sd_setImageWithURL:placeholderImage:options:]: unrecognized selector sent to instance 0x7fd2f3f0f8c0'

這個是使用SDWebImage庫時遇到的,SDWebImage庫是圖片下載及緩存池管理的神器,全都封裝好了,只需要給需要下載的圖片的url,和占位圖片就行了,這個錯誤產生的原因跟上面的一樣,所以解決方法也一樣:

- Choose every *.m file, go to File Inspector

- Go to Target Membership, check your app target.

 

3. Incompatible block pointer types sending 'void (^)(NSInteger, NSInteger)' to parameter of type 'SDWebImageDownloaderProgressBlock _Nullable' (aka 'void (^)(NSInteger, NSInteger, NSURL * _Nullable __strong)')

這個錯誤還是使用SDWebImage庫時遇到的,原因是SDWebImageDownloaderProgressBlock的Signature在新版本中變了,之前是:

typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);

后來改成這樣了:

typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);

所以在調用的時候改一下就行了:

[self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:imageName] options:SDWebImageRetryFailed|SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
    // Do something here
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    // Do something here
}];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM