2014-01-05 128 views
1

我已经通过所有相关的问题,看了看,我仍然不能得到这个工作。自定义标签不显示在自定义单元格中。故事板

我做了一个自定义单元格的.xib(foodCell.xib),并设置它的文件所有者foodCell.h。我还将标识符设置为foodCell。

enter image description here

到目前为止,所有我在自定义单元格是一个自定义标签 - priceLabel。我遇到的问题是我似乎无法为自定义标签设置值或在运行时显示它。

这里是我的foodcell.h文件:

#import <Parse/Parse.h> 

@interface foodCell : PFTableViewCell 


@property (weak, nonatomic) IBOutlet NSObject *foodCell; 

@property (weak, nonatomic) IBOutlet UILabel *priceLabel; 


@end 

这里是我的tableViewController文件I配置自定义单元格。所有其他label.text调用都可以正常工作,并显示图像。

NSLOG调用返回null

为什么我不能设置或显示这个自定义标签?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 
static NSString *CellIdentifier = @"foodCell"; 

foodCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[foodCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

} 

// Configure the cell 
cell.textLabel.text = [object objectForKey:@"foodName"]; 
cell.detailTextLabel.text = [object objectForKey:@"foodDescription"]; 
cell.imageView.file = [object objectForKey:@"foodImage"]; 
NSString *myString = @"TEST"; 
cell.priceLabel.text = myString; //[object objectForKey:@"foodPrice"]; 
NSLog(cell.priceLabel.text); 
cell.detailTextLabel.numberOfLines=0; // line wrap 
cell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight; 


return cell; 

}

+0

如果你记录cell.priceLabel你会得到什么? – sha

+0

你注册了的tableView你的笔尖? –

回答

3

注册您NibUITableViewviewDidLoad

[self.tableView registerNib:[UINib nibWithNibName:@"foodCell" bundle:nil] forCellReuseIdentifier:@"foodCellIdentifier"]; 

然后在cellForRowAtIndexPath:像下面创建细胞。

static NSString *CellIdentifier = @"foodCell"; 
foodCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
+0

这是你需要的吗? –

+0

谢谢Bilal,这绝对让我关闭。现在我将代码更改为上面发布的注册配置,我的initWithStyle:UITableViewCellStyleSubtitle不再受到尊重。我的副标题和图片已经消失,并且要查看我的客户价格标签,我必须点击单元格。我做了什么? – user3085646

+0

@ user3085646您可以在XIB中将Cell样式设置为SubTitle样式 –