UITableView注意点

来源:互联网 发布:淘宝拉卡拉pos机 编辑:程序博客网 时间:2024/06/06 00:45

一.当自定义了cell(假如名字为myCell),在控制器中想调用这个cell中的某个属性(假如为name)时,不可直接用myCell.name,这样调用会发现myCell.name中为空,实际代码应该为:

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];//假如这个cell在tableView中为第0个分区的第一行(没有分区时即为0分区)    myCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 再调用cell.name即可了

二.当在footVIew或者headerView中需要根据请求的连接来创建一些label或者button的,即根据连接的请求需要即时刷新footVIew或者headerView,则此时定义footVIew或者headerView时不可用
UILabel *headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
headerLabel.text = @"这里是表头";
_tableView.tableHeaderView = headerLabel;

这种方法。而应该用

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{    UILabel *header = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];    return header;}

并注意不要忘了
//自定义高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}

三.grpup形式的tableView是有组尾的,要想让其消失代码应为:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{        return 0.00000001;//注意不应该返回0}

另注:tableView中某些情况下,需要将组头或者组尾隐藏掉时,除了隐藏的代码外,还应该将组头或者组尾的返回高度设置为return 0.00000001;不是返回为0

四.获取指定的cell

//获取第0个分区的第1个cell        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];            ShopAnalysisType1Cell *cell = [_shopAnalysisTable cellForRowAtIndexPath:indexPath];
0 0
原创粉丝点击