我有一个TableViewCell子类,我正在尝试使用此单元格类型创建一个表。但是,该表不会显示自定义单元格内容。 细胞的值来自数据核心模型。但它没有问题,因为我也试过简单的文字,但它仍然无法正常工作。任何帮助表示赞赏。
这是我的代码:
favCell.m
#import "favCell.h"
@implementation favCell
@synthesize view;
@synthesize namelbl;
@synthesize scorelbl;
@synthesize prodimage;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
view = [[UIView alloc] initWithFrame:self.frame];
[self addSubview:view];
// initiate
prodimage = [[UIImageView alloc]initWithFrame:CGRectMake(2,20, 20, 20)];
namelbl = [[UILabel alloc]initWithFrame:CGRectMake(3,20, 40, 40)];
scorelbl = [[UILabel alloc]initWithFrame:CGRectMake(70,20, 30, 30)];
[view addSubview:namelbl];
[view addSubview:scorelbl];
[view addSubview:prodimage];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
favTable.m
#import "favTable.h"
#import "ecoAppDelegate.h"
#import "favCell.h"
@interface favTable ()
@end
@implementation favTable
@synthesize favArr;
@synthesize managedObjectContext;
@synthesize fetchedResultsController;
@synthesize favName;
@synthesize favScore;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
favCell*cell = (favCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[favCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.namelbl.text = [favName objectAtIndex:indexPath.row];
cell.scorelbl.text = [favScore objectAtIndex:indexPath.row];
cell.prodimage.image = [UIImage imageNamed:@"test1.jpg"];
return cell;
}