Reputation: 671
I want to save to database after moving some rows in the editable UITableView, But error occurred I can't find reason of error. Please advice me about my code. Thanks!!
My code :
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return indexPath.section == 0 && indexPath.row < items.count;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
isReOrderNoteList= YES;
NSString *rowContent = [items objectAtIndex:fromIndexPath.row];
[items removeObjectAtIndex:fromIndexPath.row];
[items insertObject:rowContent atIndex:toIndexPath.row];
}
//I'm using UIButton instead of Navigation barbutton.
- (IBAction)EditTable:(id)sender{
f(TableView.editing)
{
if(isReOrderNoteList)
{
[super setEditing:NO animated:NO];
[TableView setEditing:NO animated:NO];
[btn_Edit setTitle:@"Edit" forState:UIControlStateNormal];
FMDatabase *dbS = [FMDatabase databaseWithPath:dbPath];
[dbS open];
NSInteger tmp = 1;
NSLog(@" [self.items count] : %d", [ items count]); **// Print 6 !!.**
for (NSInteger i = 0; i< [items count]; i++) {
Note *list = [[Note alloc] init];
list = [items objectAtIndex:i];
NSLog(@" list.itle : %@", list.title); **//Error occurred at this line.**
NSLog(@" list.IDX : %d", list.IDX);
[dbS executeUpdate:@"Update test set sort_seq = ? where idx = ? ", [NSNumber numberWithInt:tmp], [NSNumber numberWithInt:list.IDX]];
[list release];
tmp++;
}
[dbS close];
}
//Re-init
isReOrderNoteList = NO;
}
else
{
[super setEditing:YES animated:YES];
[TableView setEditing:YES animated:YES];
[btn_Edit2 setTitle:@"Done" forState:UIControlStateNormal];
}
}
error :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteNotification title]: unrecognized selector sent to instance 0x892b550'
*** First throw call stack:
Upvotes: 0
Views: 109
Reputation: 5977
you release the note at the end of the code without do it on the "items" array
Note *list = [[Note alloc] init];
list = [items objectAtIndex:i];
NSLog(@" list.itle : %@", list.title); **//Error occurred at this line.**
NSLog(@" list.IDX : %d", list.IDX);
[dbS executeUpdate:@"Update test set sort_seq = ? where idx = ? ", [NSNumber numberWithInt:tmp], [NSNumber numberWithInt:list.IDX]];
[list release];
it should be
Note *list = [items objectAtIndex:i];
NSLog(@" list.itle : %@", list.title); **//Error occurred at this line.**
NSLog(@" list.IDX : %d", list.IDX);
[dbS executeUpdate:@"Update test set sort_seq = ? where idx = ? ", [NSNumber numberWithInt:tmp], [NSNumber numberWithInt:list.IDX]];
Upvotes: 1
Reputation: 1694
i think its Alloc init Problem ... so try to alloc the "rowContent" and other string which u use in your uitableview
Upvotes: 0