在取消固定对象后,如何从本地数据存储区正确地将数据重新加载到表中?

时间:2015-08-06 23:25:38

标签: ios objective-c uitableview parse-platform local-datastore

在我正在开发的iOS应用程序中,我有一个UITableView,其中填充了来自本地数据存储区的对象(我为此子类化了PFTableViewController)。我设置它,以便在为该特定行点击删除按钮时取消固定该对象,但在点击该按钮后,该对象仍然显示在表中。使其消失的唯一方法是下拉刷新或点击后退按钮,然后返回到此视图。

我尝试调用[tableview reloadData][self loadObjects]尝试让UITableView刷新,但不起作用。我也试过了 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]但这只会导致错误,说“第0部分中的行数无效。”

如何设置它以便删除按钮使应用程序取消固定对象并删除行/刷新数据,以便对象不再出现在表中?谢谢。这是代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.objects count];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
        NSInteger row = [tableView.indexPathForSelectedRow row];
        PFObject *delProfessor = [self.objects objectAtIndex:row];
        [delProfessor unpinInBackground];

        //These are the three ideas I've tried so far
        //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        //[tableView reloadData];
        //[self loadObjects];
    }
}

1 个答案:

答案 0 :(得分:0)

你应该从你的self.objects数组的数据源中删除对象

[self.objects removeObjectAtIndex: indexPath.row]; [self.tableView reloadData];