您的位置:首页 > 移动开发 > IOS开发

ios中自定义列表的展示

2016-09-03 15:10 253 查看
上篇讲到列表的展示使用的是自带的风格,这次我们利用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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: