您的位置:首页 > 产品设计 > UI/UE

IOS UITableview 的Cell 封装

2015-08-18 11:46 495 查看
感觉不错的代码。收藏下。

#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里实现对控件的绑定。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: