从 UITableView NSMutableArray 和 ManagedObjectContext 中删除行
我已经得到了从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下命令从表中删除行
,也可以使用以下命令从
NSMutableArray
中删除对象You can remove the row from the table with
and you can delete an object from an
NSMutableArray
with