Tableview没有显示所有PFQuery结果

时间:2014-01-23 04:18:41

标签: ios objective-c uitableview parse-platform

我在桌面视图中看到了一些意想不到的行为,我希望有人可以帮忙指出来。我在一个名为ShowContacts的Parse数据库中有63条记录。但是,我的tableview连续三次显示记录1-13。 NSLog显示所有63个都在我的“items”数组中,但它们并非都在我的tableview中显示。我错过了什么?

提前致谢, 达林

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

1 个答案:

答案 0 :(得分:0)

- (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;
}
相关问题