UITableView 表视图



1.*********************************创建表视图***************************************

1.1实例化对象
  UITableView *tv = [[UITableView alloc]  initWithFrame: self.view.bounds  style: UITableViewStyleGrouped];

1.2通过数据源代理协议获取表视图的分组数和每个分组显示的行数

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger) tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section

1.3通过数据源代理协议的方法设置表视图每个cell的显示数据

- (UITableViewCell *) tableView:(UITableView *)tableView  cellForRowAtIndexPath:(NSIndexPath *)indexPath


2.********************************dataSource数据源代理协议常用方法*************************************

2.1返回指定的分组头部的标题

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

2.2返回指定的分组尾部的标题

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

2.3返回索引标题列表,系统会自动将数组中的标题放到表视图的索引视图上,并且将索引按分组进行关联

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

2.4返回索引对应的分组

@param title     用户点击的索引位置的标题

@param index     用户点击的索引位置在索引列表中的索引

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index


3.*******************************delegate一般代理协议方法**************************************

3.1返回指定分组的表头视图

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

3.2返回指定分组的表尾视图

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

3.3返回指定位置的行的行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

3.4返回指定位置的头部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

3.5返回指定位置的尾部的高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section


4.**************************************表视图常用功能************************************

//**************************************删 除 cell****************************************

 4.1当用户点击编辑状态弹出的删除按钮或者太你家按钮时,会自动调用这个方法,在各个方法中,做删除或者插入的处理

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath


//******************************************移 动 cell*******************************************

 4.2移动cell,tableview进入编辑状态会调用

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

 4.3返回是否可以移动指定位置的cell,这个方法只有在用户实现了moveRowAtIndexPath方法后,才能看到排序的控件

- (bool)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath


5.****************************************创建搜索栏****************************************
5.1实例化搜索栏对象

    UISearchBar *sb = [[UISearchBar alloc]init];

5.2设置搜索栏的位置

  sb.frame = CGRectMake(064self.view.bounds.size.width35);

  

5.3设置搜索栏代理  

    sb.delegate = self;

5.2将搜索栏对象显示出来

    sb.showsCancelButton = YES; 


//6.************************************搜索栏代理方法**************************************

//是否可以开始编辑

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar

//已经开始编辑

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar

//是否可以结束编辑

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar

//已经结束编辑

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar

//搜索栏文本改变的时候调用,参数将文本内容传递过来

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

//当键盘的搜索按钮被点击的时候调用

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

//取消按钮被点击时调用

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值