简体   繁体   中英

Tableview not showing all of PFQuery results

I'm seeing some unexpected behavior in my tableview and I'm hoping someone can help point it out. I have 63 records in a Parse database called ShowContacts. However, my tableview is displaying records 1-13 three consecutive times. NSLog shows that all 63 are in my "items" array but they are not all being displayed in my tableview. What am I missing?

Thanks in advance, Darin

.m file

@interface ShowContactsViewController ()
@property (strong,nonatomic) NSMutableArray *items;
@end

- (void)viewDidLoad
{
[PFQuery clearAllCachedResults];
PFQuery *query = [PFQuery queryWithClassName:@"ShowContacts"];
query.cachePolicy = kPFCachePolicyIgnoreCache;
[query orderByAscending:@"Name"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (!error) {
        NSMutableArray *items = [NSMutableArray array];
        for (id obj in objects)
        {
            [items addObject:obj];
        }
        self.items = items;
        NSLog(@"%@", objects);
        NSLog(@"%lu", (unsigned long)[objects count]); // 63 records according to NSLog
        [self.myTableView reloadData];
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];
}
}
#pragma mark Table

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (nil == cell)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

    cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"Name"];

}

return cell;
}

Change - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath to

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (nil == cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

    }
    cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"Name"];
    return cell;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM