com文档,并且我将两个不同的tableViewCells使用PFQueryForTable方法在将解析对象放入单元格时进行排序。我这样做,所以当对象返回一个空白字符串,我可以将其高度降低到0.不幸的是,当我这样做时,它不会像我想要的那样运行,空白单元格被加载到第一个单元格中,而不是那个我想减少身高。如何使用两个单元格标识符对数据进行排序?
我的cellForRowAtIndexPath样子:
-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
BOOL blank = [[[object objectForKey:@"post"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@""];
static NSString *CellIdentifier = @"Cell";
static NSString *Cell2Identifier = @"Cell2";
if (!blank) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = [object objectForKey:@"post"]; //[object objectForKey:@"post"];
label.textAlignment = NSTextAlignmentCenter;
NSLog(@"posted cell");
return cell;
}
else {
UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:Cell2Identifier forIndexPath:indexPath];
if (cell2 == nil) {
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell2Identifier];
}
cell2.textLabel.text = [object objectForKey:@"post"];
NSLog(@"posted cell2");
return cell2;
}
}
可有人请点我在正确的方向?
谢谢。
将高度设置为0?这听起来像一个非常糟糕的想法!你究竟在做什么? – Fogmeister
你真正想要的是不显示空的“后”文本的对象?您应该排除在您的查询中的那些 – Moonwalkr
我接受@Fogmeister。但如果你需要,你应该实现这个( - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath)代表并返回适当的高度为您的行... – jailani