簡體   English   中英

Tableview不顯示所有PFQuery結果

[英]Tableview not showing all of PFQuery results

我在表視圖中看到一些意外的行為,希望有人可以幫助指出。 我在名為ShowContacts的解析數據庫中有63條記錄。 但是,我的表視圖連續3次顯示記錄1-13。 NSLog顯示所有63個都在我的“項目”數組中,但是它們並沒有全部顯示在我的表視圖中。 我想念什么?

預先感謝,達林

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

更改- (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