Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PFQueryTableViewController两个部分和两个数据源_Ios_Objective C_Uitableview_Parse Platform_Pfquery - Fatal编程技术网

Ios PFQueryTableViewController两个部分和两个数据源

Ios PFQueryTableViewController两个部分和两个数据源,ios,objective-c,uitableview,parse-platform,pfquery,Ios,Objective C,Uitableview,Parse Platform,Pfquery,我想要一个带有两个部分的PFQueryTableViewController: 第1部分:显示所查询的PFObjects(使用该应用程序的通讯簿联系人) 第2部分:显示数组的对象(通讯簿中所有联系人的列表) 目前,我正在设置节数: - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } İ我正在设置每个部分的行数: - (NSInteger) tableView:(UITable

我想要一个带有两个部分的
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;
}
我得到了错误:
[\uu NSArrayM objectAtIndex:]:索引2超出边界[0..1]
原因一定是
PFObject
在第1节和第2节的每一行都会被查询,并且当我在第2节上有更多对象时,它会自动超出边界并在滚动时崩溃


PFQueryTableViewController
中显示两个带有两个
数据源的节的最佳方式是什么?我是否必须在
UITableViewController
中嵌入
PFQueryTableViewController

我认为
PFQueryTableViewController
在这里不适合您。最好使用常规的
UITableViewController
,并在表中组合和显示两个查询。PFQTVC用于一个数据源。

如果我帮助了您,请将我的答案标记为正确。:)