I have an array of strings that I already show in my uitableview.
When editing is enabled for my uitableview, I try to wrap the line from the 4th line to the 3rd line, and I get EXC_BAD_ACCESS in the insert object in the index part of my code when I debug this.
[myStringsArray insertObject:name atIndex:toIndexPath.row]
However, if I do not debug and just do not build and run, I can print the next line and then it crashes without seeing EXC_BAD_ACCESS in my console.
NSLog(@"re-ordered myStringsArray array");
Here is my code for the moveRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:@"MyStrings.plist"];
NSString *name = [myStringsArray objectAtIndex:fromIndexPath.row];
[myStringsArray removeObjectAtIndex:fromIndexPath.row];
[myStringsArray insertObject:name atIndex:toIndexPath.row];
NSLog(@"re-ordered myStringsArray array");
if([myStringsArray writeToFile:path atomically: YES]){NSLog(@"write succesful");}
else {NSLog(@"write failed");}
[myTable reloadData];
}
Any ideas why he thinks I'm trying to access something that doesn't exist?
Correct me if I am wrong, but my modified array is already allocated and if the delete method worked, why not use the insert method?
thank