UITableView

1。初始化

          initWithFrame:style: 

         e.g.  [[UITableView alloc]  initWithFrame:self.view.bounds  style:UITableViewStylePlain];  //可充满整个视图

2。<UITableViewDelegate>     //事件

          myTableView.delegate = self ;

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

          tableView:viewForHeaderInSection: 

          tableView:didEndDisplayingCell:forRowAtIndexPath:   //当一个单元格滚动出屏幕时,被调用

          tableView:willDisplayCell:forRowAtIndexPath:

        - (void)tableView:(UITableView *) tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *) indexPath   //单击detail disclosure button时调用

  e.g.          //参数中的tableView可用于进行确定在view中是哪一个table view接收消息

                  - (CGFloat) tableView : (UITableView *) tableView heightForRowAtIndexPath : (NSIndexPath *) indexPath {
                                   if ( [ tableView isEqual : self.myTableView ] ) { 

                                          return 100.0f ;
                                   }
                                   return 40.0f ; 

                   }

                 - (void)    tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
                       UITableViewCell *ownerCell = [ tableView cellForRowAtIndexPath : indexPath] ;  //获取indexPath所在的cell
                       NSLog(@"Cell Title = %@", ownerCell.textLabel.text);
                  }

3。<UITableViewDataSource>   //数据源

           numberOfSectionsInTableView :   //每个表有多少个section

           tableView : numberOfRowsInSection :    //每个section有多少行

           tableView : cellForRowAtIndexPath :    //每行的单元格内容cell

    e.g.

   -(void) viewDidLoad {

           myTableView.dataSource = self ;  

           static NSString *TableViewCellIdentifier = @"MyCellId" ;   //设置cell标识

           [ self.myTableView registerClass : [ UITableViewCell class ]  forCellReuseIdentifier : TableViewCellIdentifier ] ;  

                      //注册cell以便后续进行重用,这里的cell可以是UITableViewCell,也可以是自定义的cell类

           myTableView.autoresizingMask =  UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleHeight ;    //自动伸缩 

   }

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

          UITableViewCell *cell = nil;
          if ( [ tableView isEqual:self.myTableView ] ) {
               cell = [tableView  dequeueReusableCellWithIdentifier:TableViewCellIdentifier  forIndexPath:indexPath] ; //通过之前定义的cellid获取重用
               cell.textLabel.text = [NSString stringWithFormat:。。。。] ;

               cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton ; 

                   // two useful : disclosure indicator (produces no event,

                                            detail disclosure button(fires an event,
          }
          return cell;

  }


       


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值