簡體   English   中英

自定義標簽不顯示在自定義單元格中 故事板

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

我已經查看了所有相關問題,但仍然無法實現這一點。

我創建了一個自定義單元格.xib(foodCell.xib)並將其文件所有者設置為foodCell.h。 我還將標識符設置為foodCell。

在此輸入圖像描述

到目前為止,我在自定義單元格中的所有內容都是自定義標簽 - priceLabel 我遇到的問題是我似乎無法為自定義標簽設置值或在運行時顯示它。

這是我的foodcell.h文件:

#import <Parse/Parse.h>

@interface foodCell : PFTableViewCell


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

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


@end

這是我的tableViewController文件中我配置自定義單元格的位置。 所有其他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;

}

viewDidLoad使用您的UITableView注冊Nib

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

然后在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