gpt4 book ai didi

ios - 当我滑动删除时表格单元格崩溃。获取错误的访问错误

转载 作者:行者123 更新时间:2023-11-28 22:37:53 24 4
gpt4 key购买 nike

当我滑动删除时,我的表格 View 上一直出现此错误,常规编辑按钮将其置于编辑模式,我可以用它很好地删除它,但如果我滑动单元格,它会崩溃并返回错误的访问错误.我假设某处存在一些数据对话错误,但我不明白。我可以使用编辑和点击单元格很好地删除它,但滑动会使它崩溃。我有这个创建 TableView 的 View Controller 。继承人的代码:

在我的 View Controller 中我有这段代码:

-(void)viewWillAppear:(BOOL)animated
{
[self controllerSetup];

}

-(void)controllerSetup
{


firstController = [[TeacherSplitTableController alloc] initWithStyle:UITableViewStyleGrouped];
[firstTable setDataSource:firstController];
[firstTable setDelegate:firstController];
firstController.view = firstController.tableView;
[firstController setDelegate:self];
[self tableSetUp];

}

-(IBAction)edit:(id)sender
{
if (!editting) {
editting = YES;
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(Add:)];
//Displays add button over the back button
[self.firstTable setEditing:YES animated:YES];
} else {
editting = NO;
self.navigationItem.hidesBackButton = NO;
self.navigationItem.leftBarButtonItem = NO;
[self.firstTable setEditing:NO animated:YES];
}

}

teachersplittablecontroller 代码在这里:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source

[self openDB];
NSString *sql = [NSString stringWithFormat:@"DELETE FROM Children WHERE Name = '%@' ",[listofnames objectAtIndex:indexPath.row]]; //Queries table for the childs name and returns more data.
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK){
while (sqlite3_step(statement)==SQLITE_ROW) {
}
}


[listofnames removeObjectAtIndex:indexPath.row];
[listoftickets removeObjectAtIndex:indexPath.row];
//[theDataObject.names removeObjectAtIndex:indexPath.row];
//[theDataObject.totaltickets removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self setEditing:editing animated:YES];


}

试图保持代码简洁并与问题相关。如果您需要更多代码,请询问。但是我看不出问题:(感谢所有帮助:)

最佳答案

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
[self setEditing:editing animated:YES];
}

在我看来就像一个漂亮的无限循环。

在应用程序崩溃之前是否有一些计算时间?如果没有 - 你启用僵尸了吗?

关于ios - 当我滑动删除时表格单元格崩溃。获取错误的访问错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15391203/

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