简体   繁体   English

自定义标签不显示在自定义单元格中 故事板

[英]Custom label not displaying in custom cell. Storyboard

I've looked through all the related questions and I still can't get this working. 我已经查看了所有相关问题,但仍然无法实现这一点。

I made a custom cell .xib (foodCell.xib) and set it's file owner to foodCell.h. 我创建了一个自定义单元格.xib(foodCell.xib)并将其文件所有者设置为foodCell.h。 I have also set the identifier to foodCell. 我还将标识符设置为foodCell。

在此输入图像描述

So far all I have in the custom cell is a custom label - priceLabel . 到目前为止,我在自定义单元格中的所有内容都是自定义标签 - priceLabel The problem I'm having is I can't seem to set a value to the custom label or display it at runtime. 我遇到的问题是我似乎无法为自定义标签设置值或在运行时显示它。

Here is my foodcell.h file: 这是我的foodcell.h文件:

#import <Parse/Parse.h>

@interface foodCell : PFTableViewCell


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

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


@end

Here is where in my tableViewController file I configure the custom cell. 这是我的tableViewController文件中我配置自定义单元格的位置。 All of the other label.text calls work fine, and the image displays. 所有其他label.text调用都可以正常工作,并显示图像。

My NSLOG call returns null . 我的NSLOG调用返回null

Why can't I set or display this custom label? 为什么我无法设置或显示此自定义标签?

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

} }

Register you Nib with your UITableView in viewDidLoad viewDidLoad使用您的UITableView注册Nib

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

Then in cellForRowAtIndexPath : create cell like below. 然后在cellForRowAtIndexPath :创建如下所示的单元格。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM