简体   繁体   English

Tableview不显示所有PFQuery结果

[英]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. 我在名为ShowContacts的解析数据库中有63条记录。 However, my tableview is displaying records 1-13 three consecutive times. 但是,我的表视图连续3次显示记录1-13。 NSLog shows that all 63 are in my "items" array but they are not all being displayed in my tableview. NSLog显示所有63个都在我的“项目”数组中,但是它们并没有全部显示在我的表视图中。 What am I missing? 我想念什么?

Thanks in advance, Darin 预先感谢,达林

.m file .m文件

@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

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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