iOS UITableView的一些常用属性,方法

97 篇文章 0 订阅
79 篇文章 2 订阅

1.

self.myTableView.separatorStyle =UITableViewCellSeparatorStyleNone;//隐藏cell自带的线
2.
cell.selectionStyle =UITableViewCellSelectionStyleNone;//去掉点击效果

3.

cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;//自带指向尖头

4.

self.myTableView.scrollEnabled = YES;//进制滚动

5.

 //下划线长度    

    //UIEdgeInsetsZero 下划线为屏幕的宽

    //UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>) 细微调整

    [self.myTableView setSeparatorInset:UIEdgeInsetsZero];

    //下划线颜色

    [self.myTableView setSeparatorColor:[UIColor xxxx ]];

    [self.myTableView setLayoutMargins:UIEdgeInsetsZero];

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

    UITableViewCell *cell;

    [cell setSeparatorInset:UIEdgeInsetsZero];

    [cell setLayoutMargins:UIEdgeInsetsZero];

    return cell;

}
6.UITableView协议方法
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //设置分组标识



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; //返回数据源中组的个数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;//返回数据源每组中数据个数

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;//返回每一个cell的高度

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section//自定制tableView的HeaderView(头视图)的样式

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;//返回每组头所对应的头的高度

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section//自定制tableView的FooterView(尾视图)的样式

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;//返回每组头所对应的尾的高度  

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;//执行点击每一个cell的方法







firstTableview.sectionIndexColor = [UIColorclearColor];//设置默认时索引值颜色

firstTableview.sectionIndexTrackingBackgroundColor = [UIColorclearColor];//设置选中时,索引背景颜色

//返回每个索引的内容

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

//返回索引数组

-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView;

 

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;   

}



-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{//设置删除数据源里的某一条信息

    if (editingStyle ==UITableViewCellEditingStyleDelete) {

        if (tableView ==self.mytableview) {

            [self.datasourceremoveObjectAtIndex:indexPath.row];

            [self.mytableviewbeginUpdates];

            [self.mytableviewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

            [self.mytableviewendUpdates];

        }

    }

}
- (IBAction)delete:(id)sender {

    if (self.mytableview.isEditing) {

        [self.mytableview beginUpdates];

        NSArray * selectRows = [self.mytableview indexPathsForSelectedRows];

        NSMutableIndexSet * indexpaths = [[NSMutableIndexSet alloc] init];

        for(NSIndexPath * path in selectRows){

            [indexpaths addIndex:path.row];

        }

        [self.datasource removeObjectsAtIndexes:indexpaths];

        [self.mytableview deleteRowsAtIndexPaths:selectRows withRowAnimation:UITableViewRowAnimationAutomatic];

        [self.mytableview endUpdates];

        [self.mytableview setEditing:NO animated:YES];

    }else{

        [self.mytableview setEditing:YES animated:YES];

    }

}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王 哪跑!!!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值