上篇讲到列表的展示使用的是自带的风格,这次我们利用tableviewcell来自定义列表的风格
创建tableviewcell的xib文件并拖入响应的控件
1、在头文件中继承<UITableViewDataSource,UITableViewDelegat>别忘啦引入@import "xxx.h"
声明要重写的两个方法:-(NSInteger)tableView:(UITalbeView *)tableView numberOfRowsInSection:(NSInteger)section;
-(UITableViewCell *)tableview:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
2、实现这两个方法
第一在方法体中放入return self.datasource.count;
第二个方法体中放入:
static NSString *CellIndentifier=@"cell";
//这里自定义cell
tableviewcell *cell=(tableviewcell *)[tableView dequeueReusableCellWithIdentifier:cellIndentifier ];
if(cell==nil){
NSArray *arrays=[[NSBundle mainBundle]loadNibNamed:@"tableviewcell" owner:self options:nil]
cell=(tableviewcell *)[arras objectAtIndex:0];
}
cell.textlable.text=@"dhj";
cell.namelable.text=@"kkk";
return cell;