【问题标题】:Delete row from UITableView NSMutableArray and ManagedObjectContext从 UITableView NSMutableArray 和 ManagedObjectContext 中删除行
【发布时间】:2010-12-27 17:04:18
【问题描述】:

我有从 NSMutableArray 填充的 UITableView。 NSMutableArray 是从我的 NSFetchedResultsController 创建的,它来自另一个视图

  Templates *template2 = (Templates *)[fetchedResultsController objectAtIndexPath:indexPath];
        qModalView.templateObject = template2;

并被记录到模板对象中,所以我的所有对象都以这种方式保存在我的 NSMutablArray 中。

[templateObject.questions allObjects];

现在我想在我的表格视图、数组和 templateObject.questions 中的特定对象中删除行。

请帮忙,我目前有这个:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    Questions *question_var = [questionsArray objectAtIndex:indexPath.row];

    NSLog(@"_____________________________%@", question_var.question_title);

    NSManagedObjectContext *context = [templateObject managedObjectContext];
    [context deleteObject:[templateObject.questions objectAtIndexPath:indexPath]];

    NSError *error;
    if (![context save:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }else{
        NSLog(@"deleted");
    }
}

【问题讨论】:

    标签: objective-c uitableview core-data nsmutablearray entity-relationship


    【解决方案1】:

    您可以使用

    从表中删除该行
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                     withRowAnimation:YES];
    

    你可以从NSMutableArray中删除一个对象

    [myArray removeObject:myObject];
    

    【讨论】:

    • 我如何从数据库中删除它?它是自动发生的吗?
    • 您已经在“[context deleteObject:[templateObject.questions objectAtIndexPath:indexPath]];”和“[context save:&error]”行中删除了数据库。
    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    相关资源
    最近更新 更多