UITabelView的编辑方式以及其他应用

本文所贴的代码都是主要的代码,其余内容请根据UITableView的基础知识进行自行脑补。 


自定义设置cell的选中效果

cell.selectedBackgroundView = [[[UIViewalloc] initWithFrame:cell.frame]autorelease];

cell.selectedBackgroundView.backgroundColor = [UIColorlightGrayColor];



取消系统自带的线。

_tbView.separatorStyle=UITableViewCellSeparatorStyleNone;

在创建cell的时候写,取消cell的点击阴影效果

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

//解决分割线爱你不左对齐的状况

if ([_tbVirewrespondsToSelector:@selector(setSeparatorInset:)]) {

        [_tbVirewsetSeparatorInset:UIEdgeInsetsZero];

}



       if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {

            [_tableView setSeparatorInset:UIEdgeInsetsMake(0,kContactsCell_bottomLine_Left,0,0)];

       }

        

        if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {

            [_tableView setLayoutMargins:UIEdgeInsetsMake(0,kContactsCell_bottomLine_Left,0,0)];

        }


局部刷新

刷新某一个cell

  NSIndexPath *indexPath=[NSIndexPath indexPathForRow:row inSection:0];

            [PdTabView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];


刷新某一组section

 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];

            [TYSearchTabView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];



  // tbView.editing 默认为NO  编辑状态

    tbView.editing =YES;

      // 或者是下面方法设置

    [tbViewsetEditing:isEditinganimated:YES];


【示范一】

//返回指定模块的编辑样式

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

{

   if (indexPath.section==0) {

        returnUITableViewCellEditingStyleDelete;

    }

   else {

        returnUITableViewCellEditingStyleInsert;

    }

}

//修改删除符号的文本内容

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{

   return@"删除";

}


//提交编辑操作

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


    //删除操作

    if (editingStyle==UITableViewCellEditingStyleDelete) {

        [boyGroupremoveObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationBottom];

    }

    //否则,添加操作

   else {

        [girlGroupinsertObject:@"QQ"atIndex:indexPath.row];

        [tableView insertRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationLeft];

    }

}



【示范二】

//tbView的每一行的编辑样式

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

{

    //可以选择编辑状态为复选状态。

    returnUITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    //取出点击行的cell对象  编辑状态时,每点击一个cell,就把这个cell放在删除数组中。

   UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];

    [deleteArrayaddObject:cell.textLabel.text];

}

//从选中变为不选中状态

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

   UITableViewCell *cell=[tableViewcellForRowAtIndexPath:indexPath];

    [deleteArrayremoveObject:cell.textLabel.text];

    

}



刷新某一个section的内容。用此可以来操作关闭和隐藏效果。

关闭就是这个section的cell count 为0

打开的话就是设置count 为几就是几

  [tbViewreloadSections:[NSIndexSetindexSetWithIndex:0]withRowAnimation:UITableViewRowAnimationFade];




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值