[英]Adding UIImageView to UITableview conditionally using SDWebImage
[英]Using UIImageView with SDWebImage
下午好,
我正在嘗試在TableViewController中實現SDWebImage,但是由於我的UiImageView而導致一些錯誤,導致我無法檢測到該問題,因此我需要一些幫助。 希望您能找到一些東西,因為我現在迷路了。
我收到以下錯誤:
'UIImageView'的可見@interface沒有聲明選擇器'sd_setImageWithURL:placeholderImage:'
該應用程序正在運行,緩存運行正常,但出現了該錯誤。
如果已經將“ carImage”設置為UIImageView,為什么會發生此錯誤? 我該如何解決?
CarTableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"carTableCell";
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.makeLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"id"];
cell.likes.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"likes"];
cell.comments.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"comments"];
cell.username.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"username"];
cell.refuser.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"user_ref"];
cell.modelLabel.text = [[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"user"];
NSURL * imageURL = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"imagen"]];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * carPhoto = [UIImage imageWithData:imageData];
// ERROR [cell.carImage sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
NSURL * imageURL2 = [NSURL URLWithString:[[_jsonArray objectAtIndex:indexPath.row] valueForKey:@"image"]];
NSData * imageData2 = [NSData dataWithContentsOfURL:imageURL2];
UIImage * carPhoto2 = [UIImage imageWithData:imageData2];
cell.profileImage.image = carPhoto2;
return cell;
}
那就是我的CarTableViewCell.h :
@interface CarTableViewCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UIImageView *carImage;
@property (nonatomic, strong) IBOutlet UILabel *makeLabel;
@property (nonatomic, strong) IBOutlet UILabel *modelLabel;
@property (nonatomic, strong) IBOutlet UILabel *likes;
@property (nonatomic, strong) IBOutlet UILabel *comments;
@property (nonatomic, strong) IBOutlet UILabel *username;
@property (nonatomic, strong) IBOutlet UILabel *refuser;
@property (nonatomic, strong) IBOutlet UIImageView *profileImage;
@end
提前致謝。
您必須導入UIImageView類別,以便編譯器可以看到它:
#import <SDWebImage/UIImageView+WebCache.h>
確保要導入的頭文件包含要嘗試調用的sd_xxxx類別方法。
嘗試這個:
@implementation SomeClass
-(void)doSomething {
UIView *view = [[UIView alloc] init];
[view doSomethingCool];
}
@end
您將得到相同類型的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.