iOS的 TableView 的简单用法1 - 实现数据源
2014-08-13 14:02
585 查看
【本文来自blog.csdn.net/lanmanck】
新建TableViewController和关联的类就不说了。
要显示Cell数据,做如下几步骤:
1、在Storyboard点击单个Cell,在Attributor Inspector的Identifier设置好,Accessory也设置好,例如设为Disclosure Indicator
2、在ApplicationDelegate.m里实现数据源,如果TableView有多个Section就搞多个数据源,参考博客:
iOS Storyboard 初探(三)
3、在TableViewController的实现文件中重载TableView的函数,解析如下:
设置Section个数:
4、何为Section和Cell?看下这个链接,图文并茂:
http://segmentfault.com/q/1010000000095547
新建TableViewController和关联的类就不说了。
要显示Cell数据,做如下几步骤:
1、在Storyboard点击单个Cell,在Attributor Inspector的Identifier设置好,Accessory也设置好,例如设为Disclosure Indicator
2、在ApplicationDelegate.m里实现数据源,如果TableView有多个Section就搞多个数据源,参考博客:
iOS Storyboard 初探(三)
3、在TableViewController的实现文件中重载TableView的函数,解析如下:
设置Section个数:
//返回tableview的章节数 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { //#warning Potentially incomplete method implementation. // Return the number of sections. return 2; }设置每个Section的Cell数:
//返回数组个数,指定显示多少cell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { //#warning Incomplete method implementation. // Return the number of rows in the section. //根据不同的section数值返回不同的count if(section == 1) return [self.playersArray2 count]; else return [self.playersArray count]; }设置要显示的数据:
//indexPath标示的是你要渲染的这个cell的位置,indexPath对象里有两个属性,section和row,顾名思义,可以定位某个cell。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell; if(indexPath.section == 0){ //这个匹配的字符串要在attributor inspector中的accessory设置 cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerCell"]; // Configure the cell... if(cell !=nil){ DGPlayer *player = [self.playersArray objectAtIndex:indexPath.row]; //找到数组下标 cell.textLabel.text = player.name; //赋值给当前的cell cell.detailTextLabel.text = player.game; } }else{ //这个匹配的字符串要在attributor inspector中的accessory设置 cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerCell2"]; // Configure the cell... if(cell !=nil){ DGPlayer *player = [self.playersArray2 objectAtIndex:indexPath.row]; //找到数组下标 cell.textLabel.text = player.name; //赋值给当前的cell cell.detailTextLabel.text = player.game; } } return cell; }
4、何为Section和Cell?看下这个链接,图文并茂:
http://segmentfault.com/q/1010000000095547
相关文章推荐
- iOS tableview 实现简单的搜索功能
- iOS tableview 实现简单的搜索功能
- IOS 实现3D Touch在tableView的简单应用(swift版)
- iOS UISearchController TableView 实现简单搜索功能
- iOS tableview 实现简单的搜索功能
- IOS 实现3D Touch在tableView的简单应用
- iOS TableView给力动画的简单实现(一)
- ios 简单实现tableView单选和多选功能
- iOS TableView给力动画的简单实现
- iOS tableview实现简单搜索功能
- iOS TableView给力动画的简单实现
- iOS (高仿印物App)TableView给力动画的简单实现(二)
- IOS下省市区选择器实现[基于TableView]
- IOS详解TableView——对话聊天布局的实现
- iOS 使用tableview,实现两个页面跳转及使用协议时错误记录
- UIScrollView 简单实现用法
- IOS详解TableView —— QQ好友列表的实现
- ios之TableView实现上下拉动刷新效果
- iOS学习之Table View的简单使用
- IOS_实现tableview向上滚动全屏效果与点击展开动画