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用于一个数据源。如果我帮助了您,请将我的答案标记为正确。:)