cellForRowAtIndexPath returns too many redundant results
Hi,
I am trying to retrieve data from Prase database and display it in a table view. When I query the data according to a specified category, the result is too many redundant results. For example, when the app should return 3 results it returns 9 redundant results instead. I don't know why is that happening. Here's my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *cellIdentifier = @"Cell";
PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[PFTableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier];
}
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:17];
cell.detailTextLabel.font = [UIFontfontWithName:@"Helvetica Neue Light"size:14];
//calling method to display events
//[self retrieveEventsAccordingtoCategoryandLocation:cell];
NSLog(@"Successfully retrieved %@ scores.", category);
PFQuery *query = [PFQuery queryWithClassName:@"Event"];
[query whereKey:@"eventCategory" equalTo:category];
[query findObjectsInBackgroundWithBlock:^(NSArray *events, NSError *error) {
NSLog(@"Successfully retrieved %@ scores.", events);
for (myobject in events) {
NSLog(@"%@", myobject);
cell.textLabel.text = myobject[@"eventName"];
cell.detailTextLabel.text = myobject[@"eventCity"];
}
}];
return cell;
}
Anyone knows why this is happening?
Thank you
iPhone 5s, iOS 7.0.4