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
maytelabargamalaga
Courses Plus Student 6,465 PointsParse: Delete PFRelation data
Hello guys. Thanks in advance for all advice that you can give me. I am really stack in follow point:
1.- I create a PFRelation between my user and products. 2.- The user can add some products to his/her list but can not delete.
Two taskes that I can not reach at this moment:
1.- I want to delete the item that user does not want. With the code that I wrote. I get this goal but my huge problem is that I delete also my products class where I have all my products. I want just delete the product that the user does not want and hold exactly the list of my products.
2.- I can not delete the row where the item is.
Here is my code
#import "listadoSnacks.h"
#import "editSnacks.h"
#import "editSnacksTableViewCell.h"
@interface listadoSnacks ()
@end
@implementation listadoSnacks
- (void)viewDidLoad {
[super viewDidLoad];
}
`````
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// self.currentUser =[PFUser currentUser];
self.mipedido = [[PFUser currentUser] objectForKey:@"mipedido"];
PFQuery *query = [self.mipedido query];
// [query whereKey:@"nombreProducto" notEqualTo:self.currentUser.username];
[query orderByAscending:@"nombreProducto"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error %@ %@", error, [error userInfo]);
}
else {
self.allProducts =objects;
[self.tableView reloadData];
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.allProducts count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Identificacion =@"editSnacksTableViewCell";
editSnacksTableViewCell*cell = (editSnacksTableViewCell *)[tableView dequeueReusableCellWithIdentifier:Identificacion];
if (cell == nil) {
NSArray *nib =[[NSBundle mainBundle] loadNibNamed:@"editSnacksTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
PFUser *user = [self.allProducts objectAtIndex:indexPath.row];
cell.textLabel.text =user[@"nombreProducto"];
return cell;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
PFUser *user = [self.allProducts objectAtIndex:indexPath.row];
[user deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
}];
}
}
@end