gpt4 book ai didi

iphone - 在可编辑的 uitable 中移动某些行后出错

转载 作者:行者123 更新时间:2023-11-29 04:38:24 26 4
gpt4 key购买 nike

我想在可编辑的 UITableView 中移动一些行后保存到数据库,但发生了错误我找不到错误原因。请就我的代码提出建议。谢谢!!

我的代码:

- (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];
}

}

错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteNotification title]: unrecognized selector sent to instance 0x892b550'
*** First throw call stack:

最佳答案

您在代码末尾释放了注释,而没有在“items”数组上执行此操作

    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];

应该是

    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]];

关于iphone - 在可编辑的 uitable 中移动某些行后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10749380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com