[英]Cannot click on TableView cell. (iOS, Custom cell implementation)
[英]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.