从 UITableView NSMutableArray 和 ManagedObjectContext 中删除行

发布于 2024-10-09 07:48:10 字数 1149 浏览 0 评论 0原文

我已经得到了从 NSMutableArray 填充的 UITableView。 NSMutableArray 是从我的 NSFetchedResultsController 创建的,它来自另一个视图

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

并被记录到 templateObject,所以我已经以这种方式在我的 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");
    }
}

I've got the UITableView which is populated from NSMutableArray.
NSMutableArray was created from my NSFetchedResultsController which came from another view

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

and was recorded to templateObject, so I have got all my objects in this my NSMutablArray that way.

[templateObject.questions allObjects];

Now I want to delete row in my table view , in array and in that particular object in templateObject.questions.

Please help, I have this so far:

- (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");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

所有深爱都是秘密 2024-10-16 07:48:10

您可以使用以下命令从表中删除行

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                 withRowAnimation:YES];

,也可以使用以下命令从 NSMutableArray 中删除对象

[myArray removeObject:myObject];

You can remove the row from the table with

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                 withRowAnimation:YES];

and you can delete an object from an NSMutableArray with

[myArray removeObject:myObject];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文