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