zoukankan      html  css  js  c++  java
  • tableview小结-初学者的问题

    初学者的问题主要集中在,下面几个问题:

    一、几个函数总是不被调用:例如:

    1. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;  

    这个代理不被调用的种类很多:

    1. section的count没有正确

    2. 没有设置代理

    3.如果没有设置seciton的高度,仍然不会被调用。

    二,如何在tableview右侧显示索引(拼音条)

    代码很简单:

    1. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView  
    2. {  
    3.     return _pinyinIndexArray;  
    4. }  

    前提是需要初始化_pinyinIndexArray

    1. _pinyinIndexArray = @[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#"];  


    三、获取table的header view的时候,即调用headerViewForSection:,返回空

    需要两步:

    第一步:

    在- (void)viewDidLoad中注册

    1. [TableView registerClass:[customHeaderView class] forHeaderFooterViewReuseIdentifier:HeaderIdentifier];  

    第二步:

    是现这个代理

    1. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  
    2. {  
    3.     static NSString *headerReuseIdentifier = @"TableViewSectionHeaderViewIdentifier";  
    4.   
    5.     // ****** Do Step Two *********  
    6.     M3CHeaderFooter *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerReuseIdentifier];  
    7.    // Display specific header title  
    8.    sectionHeaderView.textLabel.text = @"specific title";     
    9.   
    10.     return sectionHeaderView;      
    11. }  

    四、类似qq列表的展开,折叠的实现

    本人是从数据模型上入手,数据模型有一个bool变量isExpand标记是否折叠,tableview只是从数据模型上获取count和cell。如果isExpand=no则返回count=0.tableview自然就是一个空的分组。

    另外还有就是,可以从tableview入手:记录一个数组,记录者每一个header是否折叠。同样可以实现折叠的效果。

  • 相关阅读:
    步步为营 C# 技术漫谈 一、反射机制
    Windows API、CRT和STL
    MVC3 基本业务开发框架
    .NET实现之(WebBrowser数据采集—终结篇)
    步步为营 C# 技术漫谈 二、ASP.NET 页生命周期
    步步为营 .NET 代码重构学习笔记 十
    步步为营 .NET 代码重构学习笔记 十三
    MagicDict开发总结6 [划词 检索]
    步步为营 .NET 代码重构学习笔记系列总结
    项目多少是可以配置的?
  • 原文地址:https://www.cnblogs.com/geek6/p/4149916.html
Copyright © 2011-2022 走看看