UITableView和UITableViewCell的一些简单用法
2013-08-21 23:25
429 查看
UITableView和UITableViewCell的一些简单用法
环境:Xcode4.2,iOS5
1、增加section的标题,
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
return @"1";
}
效果如下(“意见反馈”的文字的自己添加的):
2、自定义 section 和 row 的数目(method 的名字很容易看懂,不多解释)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3、自定义 cell 的样式
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
在该 method 内部,cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;这句是设置箭头的样式。
cell.textLabel.text
= @@"CellText";设置 cell 的文字。
4、tableView 的 headerView 和 footerView
在 UITableView 的文档中,tableHeaderView 和 tableFooterView 的说明如下。
tableFooterView
Returns an accessory view that is displayed below the table.
@property(nonatomic, retain) UIView *tableFooterView
tableHeaderView
Returns an accessory view that is displayed above the table.
@property(nonatomic, retain) UIView *tableHeaderView
一般用法如下:
UIView* headerView = …
UITableView* tableView = …
tableView.tableHeaderView = headerView;
这样,我们自定义的一个headerView就会出现在tableView的上方,确切地说,应该是在tableView的table的上面(above
the table),即cell的上面。tableFooterView也是同理出现在table的下方。
5、自定义 UITableViewCell
从 UITableViewCell 的官方文档我们可以找到下面一段话
You have two ways of extending the standard
beyond the given styles. To create cells with multiple, variously formatted and sized strings and images for content, you can get the cell's content view (through its
and add subviews to it. You can also subclass
obtain cell characteristics and behavior specific to your application's needs. See "“A
Closer Look at Table-View Cells”" in Table
View Programming Guide for iOS
即表示有两种方法看自定义cell。一种是使用
and add subviews to it. 一般用法为 [cell.contentView addSubView:subView]; 另一种则是继承了。
在 UITableViewCell 的 detailTextLabel 属性中,可以设置其 Cell Style。而 Cell Style 的其中一个值
UITableViewCellStyleSubtitle A
style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.
应该可以用在一个label上下都有文字的情况。需要尝试。
6、UTableView分组(section)显示数据
详见:UTableView分组(section)显示数据
转载地址:http://blog.csdn.net/likid1412/article/details/7909090
环境:Xcode4.2,iOS5
1、增加section的标题,
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
return @"1";
}
效果如下(“意见反馈”的文字的自己添加的):
2、自定义 section 和 row 的数目(method 的名字很容易看懂,不多解释)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3、自定义 cell 的样式
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
在该 method 内部,cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;这句是设置箭头的样式。
cell.textLabel.text
= @@"CellText";设置 cell 的文字。
4、tableView 的 headerView 和 footerView
在 UITableView 的文档中,tableHeaderView 和 tableFooterView 的说明如下。
tableFooterView
Returns an accessory view that is displayed below the table.
@property(nonatomic, retain) UIView *tableFooterView
tableHeaderView
Returns an accessory view that is displayed above the table.
@property(nonatomic, retain) UIView *tableHeaderView
一般用法如下:
UIView* headerView = …
UITableView* tableView = …
tableView.tableHeaderView = headerView;
这样,我们自定义的一个headerView就会出现在tableView的上方,确切地说,应该是在tableView的table的上面(above
the table),即cell的上面。tableFooterView也是同理出现在table的下方。
5、自定义 UITableViewCell
从 UITableViewCell 的官方文档我们可以找到下面一段话
You have two ways of extending the standard
UITableViewCellobject
beyond the given styles. To create cells with multiple, variously formatted and sized strings and images for content, you can get the cell's content view (through its
contentViewproperty)
and add subviews to it. You can also subclass
UITableViewCellto
obtain cell characteristics and behavior specific to your application's needs. See "“A
Closer Look at Table-View Cells”" in Table
View Programming Guide for iOS
即表示有两种方法看自定义cell。一种是使用
contentViewproperty)
and add subviews to it. 一般用法为 [cell.contentView addSubView:subView]; 另一种则是继承了。
在 UITableViewCell 的 detailTextLabel 属性中,可以设置其 Cell Style。而 Cell Style 的其中一个值
UITableViewCellStyleSubtitle A
style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.
应该可以用在一个label上下都有文字的情况。需要尝试。
6、UTableView分组(section)显示数据
详见:UTableView分组(section)显示数据
转载地址:http://blog.csdn.net/likid1412/article/details/7909090
相关文章推荐
- UITableView和UITableViewCell的一些简单用法
- iOS UITableView简单用法
- Android中WebView的一些简单用法
- UITableView的一些基本用法
- swift里UITableView简单的用法
- UITableView的简单用法
- WebView的一些简单用法
- 结合android ,讲述iOS UITableView和UITableViewCell的用法
- UITableView最简单的用法(CHGAdapter)事件传递
- Swift中UITableView的用法(自定义UITableView和UITableViewCell)
- UITableView与UITableViewCell 简单demo
- 关于UITableView的一些用法
- UITableView的简单应用介绍
- UITableView和UITableViewCell常用属性和方法
- IOS开发中UITableView和UITableViewCell的几种样式
- ios键盘弹出挡住带自定义UITableViewCell的UITableView的解决方法
- 使UITableView中的UITableViewCell居中显示
- iOS开发UI篇章使用UItableview完成一个简单的QQ好友列表(一)
- 【精】表格(UITableView)总结(5):表单元(UITableViewCell)
- easyui datagrid detailview(subgrid)一些用法介绍