0

在我正在开发的 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];
    }
}
4

1 回答 1

0

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

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

于 2015-08-07T10:08:17.853 回答