UITextView テキストを表示するための UITableView セルがあります。を使用してセル行のテキストを削除する必要がありますUITableViewCellEditingStyleDelete
。一部のテキストを削除するために編集ボタンを使用すると、エラーが発生しました。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSMutableArray* myMutableArrayAgain = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"save"]];
// NSLog(@"array is %@",myMutableArrayAgain);
return [myMutableArrayAgain count];
}
削除機能:
-(void)editButtonPressed:(UIButton *)button{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
[tableView setEditing:![tableView isEditing] animated:YES];
NSString *buttonTitle = ([tableView isEditing]) ? @"Done" : @"Edit";
[editButton setTitle:buttonTitle forState:UIControlStateNormal];
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}
- (void)tableView:(UITableView *)tableView1
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
NSMutableArray* myMutableArrayAgain = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"save"]];
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//first delete this from the db of favorites table
NSLog(@"art id is %@",[myMutableArrayAgain objectAtIndex:indexPath.row]);
NSLog(@"indexpath is %d", indexPath.row);
[myMutableArrayAgain removeObjectAtIndex:indexPath.row];
NSLog(@"remove %d",indexPath.row);
NSArray *indexPathsToRemove = [NSArray arrayWithObject:indexPath];
NSLog(@"indextoremove %@",indexPathsToRemove);
[tableView1 deleteRowsAtIndexPaths:indexPathsToRemove withRowAnimation:UITableViewRowAnimationRight];
}
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
NSMutableArray* myMutableArrayAgain = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"save"]];
NSString *contentsToMove = [[myMutableArrayAgain objectAtIndex:[fromIndexPath row]] retain];
[myMutableArrayAgain removeObjectAtIndex:[fromIndexPath row]];
[myMutableArrayAgain insertObject:contentsToMove atIndex:[toIndexPath row]];
[contentsToMove release];
NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}
Nslog のエラー:
2013-10-07 14:29:41.939 WorkSa[3689:c07] indexpath is 0
2013-10-07 14:29:41.940 WorkSa[3689:c07] remove 0
2013-10-07 14:29:41.940 WorkSa[3689:c07] indextoremove (
"<NSIndexPath 0x8b44fa0> 2 indexes [0, 0]"
)
2013-10-07 14:29:41.941 WorkSa[3689:c07] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046
2013-10-07 14:29:41.942 WorkSafeACT[3689:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (7) must be equal to the number of rows contained in that section before the update (7), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'