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里实现对控件的绑定。
相关文章推荐
- UE3 材质概要
- Maven 使用指南(4): Maven Build 的阶段
- LeetCode Implement Queue using Stacks
- LeetCode Implement Queue using Stacks
- 移动开发UI设计、素材网站
- CocoaPods问题汇总.
- Leetcode#63||Unique Paths II
- iOS中表视图(UITableView)使用详解
- UIButton的一些使用方法
- uefi 里面如何抓到一个变量
- 19.6.1 Partitioning Keys, Primary Keys, and Unique Keys 分区键,主键,和唯一健
- Build your first Django site - QA
- Leetcode#62||Unique Paths
- UI和UX的10个不同点
- PAT 01-复杂度2. Maximum Subsequence Sum (25)&&PAT 01-复杂度1. 最大子列和问题(20)
- IOS-问题:xib关联问题[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FirstViewController" nib but the view outlet was not set.
- Leetcode#60||Permutation Sequence
- LeetCode Implement Stack using Queues
- poj 2524 Ubiquitous Religions
- LeetCode Implement Stack using Queues