Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Posted on Mar 29, 2014 12:22 AM

Reply
Question marked as Best reply

Posted on Mar 29, 2014 5:24 AM

I solved the problem:


replaced the above method with this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCellalloc] 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];

// Configure the cell to show todo item with a priority at the bottom

cell.textLabel.text = object[@"eventName"];

cell.detailTextLabel.text = object[@"eventCity"];

return cell;

}


and added this method for the query:

- (PFQuery *)queryForTable {

PFQuery *query = [PFQueryqueryWithClassName:self.parseClassName];

[query whereKey:@"eventCategory" equalTo:category];

// If no objects are loaded in memory, we look to the cache

// first to fill the table and then subsequently do a query

// against the network.

if ([self.objects count] == 0) {

query.cachePolicy = kPFCachePolicyCacheThenNetwork;

}

[query orderByDescending:@"createdAt"];

return query;

}

1 reply
Question marked as Best reply

Mar 29, 2014 5:24 AM in response to sadeemb

I solved the problem:


replaced the above method with this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCellalloc] 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];

// Configure the cell to show todo item with a priority at the bottom

cell.textLabel.text = object[@"eventName"];

cell.detailTextLabel.text = object[@"eventCity"];

return cell;

}


and added this method for the query:

- (PFQuery *)queryForTable {

PFQuery *query = [PFQueryqueryWithClassName:self.parseClassName];

[query whereKey:@"eventCategory" equalTo:category];

// If no objects are loaded in memory, we look to the cache

// first to fill the table and then subsequently do a query

// against the network.

if ([self.objects count] == 0) {

query.cachePolicy = kPFCachePolicyCacheThenNetwork;

}

[query orderByDescending:@"createdAt"];

return query;

}

cellForRowAtIndexPath returns too many redundant results

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.