iOS UIKit:UITableView
来源:互联网 发布:mac versions 注册码 编辑:程序博客网 时间:2024/06/06 19:32
UITableView是UIScollView的子类,用于显示一列数据。
UITableView 的Style 预设有两种:Plain 及Grouped。
Plain:
Grouped:
(ps:多了个外边框)
装在UITableView 里面的元素是UITableViewCell。
而UITableViewCell 预设有4种样式Style:
UITableViewCellStyleDefault:预设使用这种,若左侧ImageView没图的话,只有一行字(textLable.text)。
UITableViewCellStyleValue1:左侧为textLable.text并且左对齐,右侧为detailTextLable.text并且右对齐。
UITableViewCellStyleValue2:左侧为detailTextLable.text,右侧为textLable.text并且左对齐。
UITableViewCellStyleSubtitle:跟UITableViewCellStyleDefault大致相同,detailTextLable.text出现在textLable.text下方。
UITableViewDataSource:
UITableViewDataSource 协议定了2个要求实现的方法(tableView:cellForRowAtIndexPath 和tableView:numberOfRowsInSection)。通过实现这些方法,你告诉表视图显示多少行数据和每一行中的数据。
numberOfSectionsInTableView:This method allows the data source to inform the table view of the number ofsections that must be loaded into the table.tableView:numberOfRowsInSection:This method tells the view controller how many cells or rows have to be loaded foreach section. The section number is passed to the data source in the numberOfRowsInSection parameter. The implementation of this method is mandatory in the datasource object.tableView:cellForRowAtIndexPath:This method is responsible for returning instances of the UITableViewCell class asrows that have to be populated into the table view. The implementation of thismethod is mandatory in the data source object
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [model getRowCount];}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ; } NSUInteger row = [indexPath row]; cell.textLabel.text = [model getNameAtIndex:row]; return cell;}
UITableViewDelegate:
负责处理UITableView的表现。
协议中的可选方法让你管理表行的高度,配置节点头部和底部,对表单元重新排序等等。
- ( void ) tableView: ( UITableView * ) tableView didSelectRowAtIndexPath: ( NSIndexPath * ) indexPath { if ([ tableView isEqual: self . myTableView ]){ NSLog ( @"%@" ,[ NSString stringWithFormat: @"Cell %ld in Section %ld is selected" ,( long ) indexPath . row , ( long ) indexPath . section ]); }}
Constructing Headers and Footers in Table Views:
- ( UIView * ) tableView: ( UITableView * ) tableViewviewForHeaderInSection: ( NSInteger ) section {UILabel * result = nil ;if ([ tableView isEqual: self . myTableView ] &§ion == 0 ){result = [[ UILabel alloc ] initWithFrame: CGRectZero ];result . text = @"Section 1 Header" ;result . backgroundColor = [ UIColor clearColor ];[ result sizeToFit ];}return result ;}- ( UIView * ) tableView: ( UITableView * ) tableViewviewForFooterInSection: ( NSInteger ) section {UILabel * result = nil ;if ([ tableView isEqual: self . myTableView ] &§ion == 0 ){result = [[ UILabel alloc ] initWithFrame: CGRectZero ];result . text = @"Section 1 Footer" ;result . backgroundColor = [ UIColor clearColor ];[ result sizeToFit ];}return result ;
源码下载
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- iOS UIKit:UITableView
- iOS UIKit:UITableView
- iOS 【UIKit-UITableView】
- iOS UIKit - UITableView
- iOS开-UIKit( UITableView.h - -解读)
- UIKit--UITableView
- -[UITableView _dequeueReusableViewOfType:withIdentifier:], /SourceCache/UIKit/UIKit-2935.137/UITab
- 【UIKit-110-1】#import <UIKit/UITableView.h> 基础创建
- 【UIKit-110-3】#import <UIKit/UITableView.h>增删改移
- 【UIKit-110-4】#import <UIKit/UITableView.h>编辑模式
- 【UIKit-110-5】#import <UIKit/UITableView.h>选中行
- 【UIKit-110-6】#import <UIKit/UITableView.h>外观
- 【UIKit-110-7】#import <UIKit/UITableView.h>提前注册
- 【UIKit-110-9】#import <UIKit/UITableView.h>数据源
- UIKit框架-10.UITableView概述
- UIKit框架-12.UITableView数据刷新
- UIKit之UITableView的详细使用
- iOS UIKit类图
- VS2012下基于Glut OpenGL GL_LINE_LOOP示例程序:
- 软件工程总结
- Android之桌面组件App Widget初探
- Bitmap 保存成 icon
- linux驱动学习--第五天:第四章 Linux 内核模块 之 Linux 内核模块简介
- iOS UIKit:UITableView
- HDU-4476
- NET操作Excel的通用类ExecelHelper.cs
- linux查看文件内容
- IOS 编译ffmpeg For SDK6.1,模拟器、armv7、armv7s均可使用
- Centos --VPN虑拟局域网的配置与使用
- AspectJ_aop
- hdu 1166
- 错误报告