標籤:
感覺不錯的代碼。收藏下。
#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 封裝