首页 > 移动平台 > 详细

IOS UITableview 的Cell 封装

时间:2015-08-18 11:50:22      阅读:227      评论:0      收藏:0      [点我收藏+]

感觉不错的代码。收藏下。

#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里实现对控件的绑定。

版权声明:本文为博主原创文章,未经博主允许不得转载。

IOS UITableview 的Cell 封装

原文:http://blog.csdn.net/zz_mm/article/details/47749783

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!