cell在tableView的用法

1.先在IB上面拉界面,把空間對(duì)應(yīng)ctrl拉到h文件

2.設(shè)置代理和數(shù)據(jù)源

@interface ViewCommitViewController () <UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *commitTableView;

將tableView設(shè)置下

_commitTableView.delegate = self;

_commitTableView.dataSource = self;


進(jìn)行注冊(cè)

- (void)viewDidLoad {

[super viewDidLoad];

_commitTableView.delegate = self;

_commitTableView.dataSource = self;

[self.commitTableView registerNib:[UINib nibWithNibName:@"CommitTableViewCell" bundle:nil] forCellReuseIdentifier:@"cellID"];


在tableView進(jìn)行引用

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

CommitTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"forIndexPath:indexPath];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;

}


設(shè)置行數(shù)

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return 4;

}

這樣就自定義xib的cell了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容