zoukankan      html  css  js  c++  java
  • UITableView 使用2

     1.   首先,Controller需要实现两个  delegate ,分别是  UITableViewDelegate 和  UITableViewDataSource

       2.然后 UITableView对象的 delegate要设置为 self。

       3. 然后就可以实现这些delegate的一些方法拉。

           (1)- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;   

             这个方法返回 tableview 有多少个section 

            

    1. //返回有多少个Sections  
    2. (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView   
    3.  
    4.     return 1;  
    5.  
     

             (2)- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;

            这个方法返回   对应的section有多少个元素,也就是多少行。

            

    1. (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   
    2.  
    3.     return 10;  
    4.  
     

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

                      这个方法返回指定的 row 的高度。

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

                      这个方法返回指定的 section的header view 的高度。

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

                      这个方法返回指定的 section的footer view 的高度。

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

                    返回指定的row 的cell。这个地方是比较关键的地方,一般在这个地方来定制各种个性化的 cell元素。这里只是使用最简单最基本

                    的cell 类型。其中有一个主标题 cell.textLabel 还有一个副标题cell.detailTextLabel,  还有一个 image在最前头 叫 

                    cell.imageView.  还可以设置右边的图标,通过cell.accessoryType 可以设置是饱满的向右的蓝色箭头,还是单薄的向右箭头,

                    还是勾勾标记。  

                   

    1. (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath   
    2.  
    3.     static NSString showUserInfoCellIdentifier @"ShowUserInfoCell" 
    4.     UITableViewCell cell [tableView_ dequeueReusableCellWithIdentifier:showUserInfoCellIdentifier];  
    5.     if (cell == nil)  
    6.      
    7.         // Create cell to display an ingredient.  
    8.         cell [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle   
    9.                                        reuseIdentifier:showUserInfoCellIdentifier]   
    10.                 autorelease];  
    11.      
    12.       
    13.     // Configure the cell.  
    14.     cell.textLabel.text=@"签名" 
    15.     cell.detailTextLabel.text [NSString stringWithCString:userInfo.user_signature.c_str()  encoding:NSUTF8StringEncoding];  
    16.          
    17.           
     

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

                   返回指定的 section 的header的高度

                    

    1. (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section  
    2.  
    3.     if (section ==0)  
    4.         return 80.0f;  
    5.     else  
    6.         return 30.0f;  
    7.  
     

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

                   返回指定的section 的 header  的 title,如果这个section header  有返回view,那么title就不起作用了。

                    

    1. (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  
    2.  
    3.     if (tableView == tableView_)  
    4.      
    5.         if (section == 0)   
    6.          
    7.             return @"title 1" 
    8.           
    9.         else if (section == 1)   
    10.          
    11.             return @"title 2" 
    12.           
    13.         else   
    14.          
    15.             return nil;  
    16.          
    17.       
    18.     else   
    19.      
    20.         return nil;  
    21.      

  • 相关阅读:
    java applet传参和接收
    如何开启to 日志
    Linux重启网卡的方法
    java下载远程文件到本地
    下载文件使用缓存(一次性读取到内存),优化性能(注意静态对象修改需要加锁)
    浏览器地址传中文解决方法 URLEncoder.encode(str,"编码") new URLDecoder().decode(str,"编码")
    根据端口号(http和https的)跳转到不同的工程
    删除某个文件夹下的所有文件(或一类执行文件)
    http和https访问jsp传送中文参数
    根据取模选择不同的列表
  • 原文地址:https://www.cnblogs.com/cnsec/p/11515920.html
Copyright © 2011-2022 走看看