UItableView中滑动删除 cell

主要是就是两个函数
一:
- ( void) tableView:( UITableView  *) tableView  commitEditingStyle:( UITableViewCellEditingStyle) editingStyle  forRowAtIndexPath:( NSIndexPath  *) indexPath 
相应 editingStyle事件处理
在这里主要相应
UITableViewCellEditingStyleDelete:

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

在这个函数中设置那个cell设置成 什么样的editingStyle删除,插入,无
UITableViewCellEditingStyleDelete
UITableViewCellEditingStyleInsert
UITableViewCellEditingStyleNone

需要注意的问题:在删除对应cell中的内容时,也要删除这个cell,否则运行时显示效果就像没有刷新 一样,多出一个cell。而使用
[tableView reloadData];[self loadView];刷新都不管用。必须使用 deleteRowsAtIndexPaths: withRowAnimation: 函数删除这个cell

     [ tableView  deleteRowsAtIndexPaths: [ NSArray  arrayWithObject: indexPath ]  withRowAnimation: UITableViewRowAnimationFade ];

[tableView reloadData];据说reloadData只是从新加载表项内容,而不会重新设置表内cection中cell的个数。



#pragma mark Table view methods



- ( UITableViewCellAccessoryType) tableView:( UITableView  *) tableView  accessoryTypeForRowWithIndexPath:( NSIndexPath  *) indexPath
{
     //NSLog(@"accessoryTypeForRowWithIndexPath");
     if0  ==  indexPath . section  ){
         ifindexPath . row  ==  [ m_URLArray  count ]){
             return  UITableViewCellAccessoryDetailDisclosureButton;
         }
         GFdataURL  * currentURl ;
         currentURl  =  [[[ GFdataURL  alloc ]  init ]  autorelease ];
         currentURl  =  [ m_URLArray  objectAtIndex:  indexPath . row ];
         //[currentURl release];
        //int i = [indexPath row];

         if ([ currentURl . m_strSubscribe  isEqualToString: @"y" ]){
             return  UITableViewCellAccessoryCheckmark;
         } else {
             return  UITableViewCellAccessoryNone;
         }
     } else {
         return  UITableViewCellAccessoryDetailDisclosureButton;
     }
   
}

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


- ( void) tableView:( UITableView  *) tableView  accessoryButtonTappedForRowWithIndexPath:( NSIndexPath  *) indexPath
{
     //NSLog(@"accessoryButtonTappedForRowWithIndexPath");
    //NSInteger sectionSelect = [indexPath section];
    //NSInteger rowSelect = [indexPath row];
    //NSLog(@"选中了%d--%d",sectionSelect,rowSelect);

     switch( indexPath . section ){
         case  0 :
             //资讯设置
             ifindexPath . row  ==  [ m_URLArray  count ]){
                 m_addNewsURL  =  [[ addNewsURL  alloc ]  initWithNibName: @"addNewsURL"  bundle: nil ];
                 [ self . navigationController  pushViewController: m_addNewsURL  animated: YES ];
             }
             break;
         case  1 :
             //货币设置
             switch( indexPath . row ){
                 case  0 :
                     //跳转到默认类型 设置页面
                     m_defaltType  =  [[ currencySettingForDefaultTypeViewController  alloc ]  initWithNibName: @"currencySettingForDefaultType"  bundle: nil ];
                     m_defaltType . isDefaultType  =  YES;
                     [ self . navigationController  pushViewController: m_defaltType  animated: YES ];
                     break;
                 case  1 :
                     //跳转到兑换类型 设置页面
                     m_defaltType  =  [[ currencySettingForDefaultTypeViewController  alloc ]  initWithNibName: @"currencySettingForDefaultType"  bundle: nil ];
                     m_defaltType . isDefaultType  =  NO;
                     [ self . navigationController  pushViewController: m_defaltType  animated: YES ];
                     break;
        
                 default  :
                    ;
             }
           
             break;
         default  :
            ;
     }
   
   
}


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


//for section 0 中的滑动删除效果

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    if( (0 == indexPath.section) && (indexPath.row != [m_URLArray count]) ){
       return UITableViewCellEditingStyleDelete;
    }else{
        return UITableViewCellEditingStyleNone;
    }   
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/



// Override to support editing the table view.

- ( void) tableView:( UITableView  *) tableView  commitEditingStyle:( UITableViewCellEditingStyle) editingStyle  forRowAtIndexPath:( NSIndexPath  *) indexPath  {
     //NSLog(@"commitEditingStyle");
     if ( editingStyle  ==  UITableViewCellEditingStyleDelete{
      
         GFdataURL  * currentURl ;
         currentURl  =  [[ GFdataURL  alloc ]  init ];
         //currentURl = [m_URLArray objectAtIndex: indexPath.row];
         currentURl  =  [[ m_URLArray  objectAtIndex: indexPath . row ]  retain ];
       
         GFDBC  * mydatabase;
         mydatabase  = [[ GFDBC  alloc ]  init ];
         [ mydatabase  deleteURL: currentURl . m_strURL ];
         [ currentURl  release ];
         currentURl  =  nil;
         if( m_URLArray  != nil ){
             [ m_URLArray  release ];
             m_URLArray  = [[ NSMutableArray  alloc ]  init ];
         }
         m_URLArray  =  [[ mydatabase  getAllURL ]  retain ];
         //
         [ mydatabase  release ];
         //[m_tableView deleteRowsAtIndexPaths:indexPath.row withRowAnimation:UITableViewRowAnimationFade];
        //[tableView reloadData];
        //[self loadView];

         [ tableView  deleteRowsAtIndexPaths: [ NSArray  arrayWithObject: indexPath ]  withRowAnimation: UITableViewRowAnimationFade ];
     } 
     else if ( editingStyle  ==  UITableViewCellEditingStyleInsert{
         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
     } 
   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值