新建一個繼承自UITableViewCell
的子類,比如XMGTgCell
@interface XMGTgCell : UITableViewCell
@end
新建一個xib文件(文件名最好跟類名一致屑咳,比如XMGTgCell.xib)
- 修改cell的class為XMGTgCell
Snip20150629_245.png
- 綁定循環(huán)利用標識
Snip20150629_246.png
- 添加子控件慷丽,設置子控件約束
Snip20150629_251.png
- 將子控件連線到類擴展中
@interface XMGTgCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;
@end
在XMGTgCell.h文件中提供一個模型屬性款熬,比如XMGTg模型
@class XMGTg;
@interface XMGTgCell : UITableViewCell
/** 團購模型數據 */
@property (nonatomic, strong) XMGTg *tg;
@end
在XMGTgCell.m中重寫模型屬性的set方法
- 在set方法中給子控件設置模型數據
- (void)setTg:(XMGTg *)tg
{
_tg = tg;
// .......
}
在控制器中
- 注冊xib文件
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([XMGTgCell class]) bundle:nil] forCellReuseIdentifier:ID];
- 給cell傳遞模型數據
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 訪問緩存池
XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 設置數據(傳遞模型數據)
cell.tg = self.tgs[indexPath.row];
return cell;
}