我对每个单元格都有一个按钮,一旦单击它就会从 Parse 后端删除每个单独的对象。我将其设置为reloadData
在块中成功,如下所示:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
PFRelation *relation = [self.currentUser relationforKey:@"watching"];
[[relation query] findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
// There was an error
} else {
// NSLog(@"%@", objects);
self.watchingEvents = objects;
[self refreshTableView];
}
}];
}
-(IBAction) deleteButtonAction:(id) sender
{
[SVProgressHUD showWithStatus:@"Removing from Watch List..."];
PFRelation *relation = [self.currentUser relationforKey:@"watching"];
[relation removeObject:self.selectedEvent];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error)
{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlertView show];
}
else
{
[SVProgressHUD showSuccessWithStatus:@"Removed from Watch List!"];
[self refreshTableView];
}
}];
}
-(void)refreshTableView
{
[self.tableView reloadData];
}
但它似乎没有更新tableView,单元格仍然显示(即使它已经消失了,因为如果我离开并再次打开视图,则会viewWillAppear
使用相同的reloadData
函数调用并且项目会像它应该的那样消失。所以我知道这些功能在工作,因为它显然在工作viewWillAppear
。不知道为什么一旦块成功运行它就不能工作,因为警报运行良好,就像我输入的任何 NSLog 消息一样?