新建一個繼承自UITableViewCell
的子類,比如XMGTgCell
@interface XMGTgCell : UITableViewCell
@end
在XMGTgCell.m文件中
- 重寫
-initWithStyle:reuseIdentifier:
方法
- 在這個方法中添加所有的子控件
- 給子控件做一些初始化設置(設置字體、文字顏色等)
添加子控件的完整約束
/**
* 在這個方法中添加所有的子控件
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// ......
}
return self;
}
在XMGTgCell.h文件中提供一個模型屬性,比如XMGTg模型
@class XMGTg;
@interface XMGTgCell : UITableViewCell
/** 團購模型數據 */
@property (nonatomic, strong) XMGTg *tg;
@end
在XMGTgCell.m中重寫模型屬性的set方法
- (void)setTg:(XMGTg *)tg
{
_tg = tg;
// .......
}
在控制器中
[self.tableView registerClass:[XMGTgCell class] forCellReuseIdentifier:ID];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 訪問緩存池
XMGTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 設置數據(傳遞模型數據)
cell.tg = self.tgs[indexPath.row];
return cell;
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。