感觉不错的代码。收藏下。
#import "GDBookTableViewCell.h"
#import "GDBook.h"
@interface GDBookTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconLabel;
@property (weak, nonatomic) IBOutlet UILabel *authorLabel;
@property (weak, nonatomic) IBOutlet UILabel *booknameLabel;
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;
@end
@implementation GDBookTableViewCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"bookCell";
GDBookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"GDBookTableViewCell" owner:nil options:nil] lastObject];
}
return cell;
}
-(void)setBook:(GDBook *)book
{
_book = book;
self.booknameLabel.text = book.name;
}
@end
调用的地方:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GDBookTableViewCell *cell = [GDBookTableViewCell cellWithTableView:tableView];
// 设置数据
GDBook *book = self.books[indexPath.row];
cell.book = book;
return cell;
}
然后在
setBook里实现对控件的绑定。