1

我想有PFQueryTableViewController两个部分:

  • 第 1 部分:显示PFObjects查询的(通讯录中正在使用应用程序的联系人)
  • 第 2 部分:显示数组的对象(地址簿中所有联系人的列表)

目前我正在设置部分的数量:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

我正在设置每个部分的行数:

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        return [self.contacts count];
    }
    else
    {
        return [self.objects count];
    }
    return 1;
}

当我尝试显示单元格的内容时,滚动时出现崩溃:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";
    PFTableViewCell *cell = (PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    }

    if (indexPath.section == 0)
    {
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    name.text = object[@"username"];
    [cell addSubview:name];
    }
    else
    {
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
        name.text = [self.contacts objectAtIndex:indexPath.row];
        [cell addSubview:name];
        NSLog(@"%@", [self.contacts objectAtIndex:20]);
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

我收到错误消息:[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]原因一定是因为PFObject第 1 节和第 2 节的每一行都被查询,并且由于第 2 节中有更多对象,它会在滚动时自动越界并崩溃。

在 a中显示两个带有两个dataSources 的部分的最佳方法是PFQueryTableViewController什么?我必须在 a 中嵌入PFQueryTableViewControlleraUITableViewController吗?

4

1 回答 1

1

我认为 aPFQueryTableViewController在这里不会很好地为您服务。使用常规可能会更好UITableViewController,并且将两个查询组合并显示在表中。PFQTVC 旨在与一个数据源一起使用。

于 2014-08-14T16:37:25.990 回答