我想有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中显示两个带有两个dataSource
s 的部分的最佳方法是PFQueryTableViewController
什么?我必须在 a 中嵌入PFQueryTableViewController
aUITableViewController
吗?