Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
patrick tagliaferro
5,399 Pointsslide to delete from parse
I have a table pulling from a relation in parse. I enabled the slide to delete to delete the item from the backend. The code right now works in terms that it will delete the object from the relation but it wont actually delete from the table right away, I have to reload the app. Anyone now how to make it delete the cell right away? Like when you delete a phone call.
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
//Remove from Backend
[self.houseRelation removeObject:self.house];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
}
}];
[tableView reloadData];
}
}
1 Answer
Stone Preston
42,016 Pointsthe problem is you are removing it from the back end, and then reloading your tableView. The array your tableView gets the data from never gets updated. You need to update your data source after you remove the item from the backend, then reload the table (query the back end again after removing the item from it and assigning the return value of the query to your array)
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
//Remove from Backend
[self.houseRelation removeObject:self.house];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
///user was saved, now you need to query the back end again and assign the return array to whatever you are using as the data source and reload the tableView here
}
}];
}
}
patrick tagliaferro
5,399 Pointspatrick tagliaferro
5,399 PointsWorked perfect! I knew I was missing something.