iOS 的UITableView 会有一些代理方法,这里时编辑和删除的一些简单的方法
// 确认编辑 实现的一些方法
-(
void
)tableView:(
UITableView
*)tableView commitEditingStyle:(
UITableViewCellEditingStyle
)editingStyle forRowAtIndexPath:(
NSIndexPath
*)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete )
{
NSString *key = self . array [indexPath. section ];
NSMutableArray *array = self . dic [key];
NSLog ( @"%ld" ,array. count );
[ PerSonDate dictionaryDeleteDate :array[indexPath. row ]];
self . dic = [ PerSonDate shareDictionaryDate ]. date ;
self . array = [ PerSonDate shareDictionaryDate ]. array ;
if ( self . array . count != count )
{
[ self . tableView reloadData ];
count = ( int ) self . array . count ;
}
else
{
NSArray *aa = @[ indexPath ] ;
[ self . tableView deleteRowsAtIndexPaths :aa withRowAnimation : UITableViewRowAnimationLeft ];
}
}
}
if (editingStyle == UITableViewCellEditingStyleDelete )
{
NSString *key = self . array [indexPath. section ];
NSMutableArray *array = self . dic [key];
NSLog ( @"%ld" ,array. count );
[ PerSonDate dictionaryDeleteDate :array[indexPath. row ]];
self . dic = [ PerSonDate shareDictionaryDate ]. date ;
self . array = [ PerSonDate shareDictionaryDate ]. array ;
if ( self . array . count != count )
{
[ self . tableView reloadData ];
count = ( int ) self . array . count ;
}
else
{
NSArray *aa = @[ indexPath ] ;
[ self . tableView deleteRowsAtIndexPaths :aa withRowAnimation : UITableViewRowAnimationLeft ];
}
}
}
//每一行的编辑样式
-(
UITableViewCellEditingStyle
)tableView:(
UITableView
*)tableView editingStyleForRowAtIndexPath:(
NSIndexPath
*)indexPath
{
if (indexPath. section == 0 ) {
return UITableViewCellEditingStyleDelete ;
}
return UITableViewCellEditingStyleInsert ;
{
if (indexPath. section == 0 ) {
return UITableViewCellEditingStyleDelete ;
}
return UITableViewCellEditingStyleInsert ;
}
// Yes编辑和 NO不编辑
-(
void
)setEditing:(
BOOL
)editing animated:(
BOOL
)animated
{
[ super setEditing :editing animated :animated];
//[self.tableView setEditing:YES animated:YES];
if ( flag == 0 )
{
[ self . tableView setEditing : YES animated : YES ];
flag = 1 ;
}
else if ( flag == 1 )
{
[ self . tableView setEditing : NO animated : YES ];
flag = 0 ;
}
}
{
[ super setEditing :editing animated :animated];
//[self.tableView setEditing:YES animated:YES];
if ( flag == 0 )
{
[ self . tableView setEditing : YES animated : YES ];
flag = 1 ;
}
else if ( flag == 1 )
{
[ self . tableView setEditing : NO animated : YES ];
flag = 0 ;
}
}
// 哪一行可以编辑
-(
BOOL
)tableView:(
UITableView
*)tableView canEditRowAtIndexPath:(
NSIndexPath
*)indexPath
{
if (indexPath. section == 1 && indexPath. row == 0 ) {
return YES ;
}
return YES ;
{
if (indexPath. section == 1 && indexPath. row == 0 ) {
return YES ;
}
return YES ;
}