http://blog.csdn.net/zomfice/article/details/51767973
Cell注冊(cè)的兩種方式
//1.
tableView registerNib:(nullable UINib *) forCellReuseIdentifier:(nonnull NSString *)
//2.
tableView registerClass:(nullable Class) forCellReuseIdentifier:(nonnull NSString *)
Cell注冊(cè)的形式:
(1)系統(tǒng)cell
// 1.注冊(cè)
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
// 2.不注冊(cè)
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
(2)自定義cell
//1.注冊(cè)
[self.tableView registerClass:[xxxxCell class] forCellReuseIdentifier:@"cell"];
xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//2.不注冊(cè)
xxxxCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell==nil) {
cell=[[xxxxCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
(3)自定義cellXib注冊(cè)
// 1.注冊(cè)
[tableView registerNib:[UINib nibWithNibName:@"xxxxViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
xxxxCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// 2.不注冊(cè)
xxxxCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@“xxxxCell" owner:self options:nil]lastObject];
}
(4)storyboard自定義cell
簡(jiǎn)述:在storyBoard中拖出一個(gè)TableViewController挣菲,編輯controller上的Cell搓侄,可以拖出Imageview和Label,然后建立一個(gè)基于UITableViewCell類xxxxViewCell逐哈,將StoryBoard上的空間拖對(duì)應(yīng)的屬性到xxxxViewCell的.h文件中,同時(shí)在StoryBoard中選中TableView—>content設(shè)置是動(dòng)態(tài)cell Dynamic Prototypes 還是靜態(tài)cell Static Cells同時(shí)可以設(shè)置Cell的rows height,然后選中Cell關(guān)聯(lián)創(chuàng)建的Cell類xxxxViewCell同時(shí)設(shè)置Identifider 如:cellId
復(fù)用:
xxxxViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId" forIndexPath:indexPath];