tableview小结

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

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

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

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

1. section的count没有正确

2. 没有设置代理

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


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

代码很简单:

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return _pinyinIndexArray;
}

前提是需要初始化_pinyinIndexArray

    _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中注册

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

第二步:

是现这个代理

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *headerReuseIdentifier = @"TableViewSectionHeaderViewIdentifier";

    // ****** Do Step Two *********
    M3CHeaderFooter *sectionHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerReuseIdentifier];
   // Display specific header title
   sectionHeaderView.textLabel.text = @"specific title";   

    return sectionHeaderView;    
}

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

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

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

五、cell的prepareForReuse的接口。

在tableview的代理方法中cellForRowAtIndexPath:,调用dequeueReusableCellWithIdentifier的时候,cell的prepareForReuse调用。

比如:一个屏幕可以展示10行cell,而你的table有15行。当你滑动到12个cell的时候,第一个cell已经完全消失在屏幕外了,那么第12个cell将复用第一个cell的内存。

这样的话:开发者可以在prepareForReuse做一些,不能复用的一些工作。防止图片显示错乱。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值