2014-02-12 93 views
-1

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; 
    } 
} 

可有人请点我在正确的方向?

谢谢。

+2

将高度设置为0?这听起来像一个非常糟糕的想法!你究竟在做什么? – Fogmeister

+0

你真正想要的是不显示空的“后”文本的对象?您应该排除在您的查询中的那些 – Moonwalkr

+0

我接受@Fogmeister。但如果你需要,你应该实现这个( - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath)代表并返回适当的高度为您的行... – jailani

回答

0

OK,从您的评论您当前正在创建这样的查询...

- (PFQuery *)theQuery 
{ 
    PFQuery *posts = [PFUser query]; 
    [posts whereKey:@"location" nearGeoPoint:self.myLocation withinKilometers:10.0]; 
    [posts includeKey:self.textKey]; 
    return posts; 
} 

因此,所有你需要做的就是添加一个where条件吧...

[posts whereKey:@"theText" notEqualTo:@""]; 

这将停止发送空白文本帖子。

+0

不幸的是,这不起作用,因为“notEqualTo:”方法想要和id,而不是字符串。有什么我错过了吗? – user3159704

+0

@ user3159704来自文档... https://parse.com/docs/ios_guide#queries/iOS这就是'notEqualTo'的工作原理。 – Fogmeister

+1

非常感谢你,你真棒!所以对象键的默认值是“(undefined)”,所以“whereKey:notEqualTo:”方法无法工作。然而,您将解析文档引入了我的注意力,我能够弄清楚未定义对象键的正确方法是使用“whereKeyExists:”所以非常感谢您,请原谅我的无知。 – user3159704

相关问题