UITableView

9 篇文章 0 订阅

将tableview的边框 四角改为圆角的

Radius 代表弧度半径  

table.layer.cornerRadius = 10;

    table.layer.borderWidth = 1;//边框的透明度?,是的我确实用它改了透明度!

            be Continued。。。

// 添加 tableviewCell 右侧的小箭头图标

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];


//设置tableview cell的边框 颜色

tableview.separatorColor = [UIColor redColor];

tableViewStyle  为 Grouped 时tableview 只显示已有的cell,下面没有的不补全(即没有多余横线)

1. 隐藏tableView的滚动条

    leftTableView.showsVerticalScrollIndicator = NO;

2.在tablev 的右侧添加一个索引的控件!例如通信录快捷收索!  tableview 必须是分组的 例如 title 为key 我们会利用下面的委托

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

    return key;

}

//创建编辑按钮

-(void) CreateBarBtn

{

    mEdit = [[UIBarButtonItemalloc] initWithTitle:@"编辑"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(pressEdit)];

    mFinish= [[UIBarButtonItemalloc] initWithTitle:@"结束"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(pressFinish)] ;


 mDeleteBtn = [[UIBarButtonItemalloc] initWithTitle:@"删除"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(pressDelete)] ;

   mIsEdit = NO ;

   self.navigationItem.rightBarButtonItem = mEdit ;

    mIsDelete = NO ;

}

-(void) pressDelete

{

    for (int k = 0 ; k < [mDeleteArray count] ; k++) 

    {

       NSString* strDelete = [mDeleteArray objectAtIndex:k] ;

        for (int i = 0 ; i < [mArrayData count] ; i++)

        {

            NSMutableArray* smallArray = [mArrayData objectAtIndex:i] ;

            for (int j = 0  ; j < [smallArray count]; j++) {

                     NSString* str = [smallArray objectAtIndex:j] ;

                if ([strDelete isEqualToString:str]) 

                {

                    [smallArray removeObject:str] ;

                }

            }

        }        

    }

    [mTableViewreloadData] ;

}

//开启编辑状态

-(void) pressEdit

{

    self.navigationItem.leftBarButtonItem = mDeleteBtn ;

    self.navigationItem.rightBarButtonItem = mFinish ;

    [mTableViewsetEditing:YESanimated:YES] ;

    mIsEdit = YES ;

  mIsDelete = YES ;

}

//结束编辑状态

-(void) pressFinish

{

    self.navigationItem.leftBarButtonItem = nil ;

    self.navigationItem.rightBarButtonItem = mEdit ;

    [mTableView setEditing:NO animated:YES] ;

    mIsEdit = NO ;

    mIsDelete = NO ;

}

//设置组标题

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

{

    return [NSString stringWithFormat:@"%d组",section];

}

//设置结尾标题

-(NSString*) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"%d组结束",section];

}

//设置组头高度

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 80 ;

}

//设置单元格行高

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return 60 ;

//    if (indexPath.row % 2 == 0) {

//        return 80 ;

//    }

//    else

//    {

//        return 40 ;

//    }

}

//选中某行时函数被调用

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

{

    if (mIsDelete == YES

    {

        NSString* strDelete = [[mArrayData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] ;

        [mDeleteArray addObject:strDelete] ;

    }    else

    {

   RootVC* rootVC = [[RootVC alloc] init] ;

        //rootVC.mArrayData = mArrayData ;

        [self.navigationController pushViewController:rootVC animated:YES] ;

    }

}

//当编辑操作完成提交时被调用

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

{

    NSLog(@"delete!!!") ;

    // 获得当前数组指针

    NSMutableArray* smallArray = [mArrayData objectAtIndex:indexPath.section] ;

    //两种数据删除方式

//    NSString* str =  [smallArray objectAtIndex:indexPath.row] ;

//    [smallArray removeObject:str] ;

    [smallArray removeObjectAtIndex:indexPath.row] ;

[tableView deleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationRight];

    //一定要重新加载数据 ?--->为什么呢?

    [tableView reloadData] ;

}

//更改删除按钮文字

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

{

     if (indexPath.row % 2 == 0) {

        return @"删除";

   }

    else

    {

       return @"Delete";

    }

}

//取消选择某行时被调用

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

{

    if (mIsDelete == YES)

    {

        NSString* str = [[mArrayData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] ; 

        for (int i = 0 ; i  < [mDeleteArray count] ; i++) {

            NSString* strDelete = [mDeleteArray objectAtIndex:i];

            if ([str isEqualToString:strDelete])

            {

                [mDeleteArray removeObject:strDelete];

            }

        }

    }

    NSLog(@"%d行取消",indexPath.row) ;

}

//即将开始编辑

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

{

    NSLog(@"will Begin Edit!");

}

//已经结束编辑被调用

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

{

    NSLog(@"已经结束编辑");

}

//是否可以进行编辑操作

-(BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnYES ;

    if (indexPath.row % 2 == 0) {

      return YES ;

   }   else

    {

       return NO ;

    }

}

//决定编辑按钮风格 滑动删除按钮的出现

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

{

    //多组操作风格

    returnUITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;

}

//是否可以移动单元格

-(BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnYES ;

}

//交换两个单元格子的位置

-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

   

}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值