2013-12-17 19 views
0

当我在TableView中设置原型单元格的标识符时,我陷入了一个问题,故事板无法编译。我认为我已经完成了一切,扩展了UITableViewCell并在该类中创建了IBOutlets,为我的TableView创建了一个DataSource和Delegate,并实现了必要的方法和所有内容。当原型单元格的标识符设置时,故事板编译失败

我的单元有4个UIImages,有8个UILabels和1个UIButton。当我全部删除它们时,故事板会用标识符编译。但是,它并不是出现这些组件。令人惊讶的是,它编译了这四个中的两个UIImage,并且不会编译其他任何内容。另外,如果我删除了为IBOutlets创建的所有UI项目,它并不会失败。一旦它们全部被删除,那些没有IBOutlet的东西就会出现在表格中,但是执行并不在VenueCardCell类中。

我注意到失败并不取决于我的VenueCardCell类的存在。即使该类不存在,它也会失败。

在所有情况下,当我没有为原型单元格设置标识符时,所有内容都会编译。但是桌子上什么都没有显示出来。事实上,即使编译时,表中也没有显示出来。

我不明白我在这里做错了什么。请帮忙!让我知道你是否需要在这里看到其他东西。

这是我的类,它扩展UITableViewCell

@interface VenueCardCell : UITableViewCell 

@property (weak, nonatomic) IBOutlet UIImageView *vImage; 
@property (weak, nonatomic) IBOutlet UIButton *favoriteButton; 
@property (weak, nonatomic) IBOutlet UILabel *vnLabel; 
@property (weak, nonatomic) IBOutlet UILabel *vaLabel; 
@property (weak, nonatomic) IBOutlet UILabel *vdLabel; 
@property (weak, nonatomic) IBOutlet UILabel *waitLabel; 
@property (weak, nonatomic) IBOutlet UILabel *rwaitLabel; 
@property (weak, nonatomic) IBOutlet UILabel *ratioLabel; 
@property (weak, nonatomic) IBOutlet UILabel *fLabel; 

@end 

@implementation VenueCardCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end 

这是我的ViewController类 - (为简单起见,我已经硬编码了一些值,所以我只能看到同一个小区的10倍)

@interface HomeViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 

@property (weak, nonatomic) IBOutlet UITableView *tableView; 

@end 

@implementation HomeViewController 

static NSString *CellIdentifier = @"VenueCard"; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSInteger numberOfRows = 10; 
    return numberOfRows; 
} 

- (VenueCardCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView registerClass:[VenueCardCell class] forCellReuseIdentifier:CellIdentifier]; 
    VenueCardCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    return cell; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

回答

2

好吧,我发现了这个问题。几个小时前,当我创建ViewController时,我已经将Cell的IBOutlets添加到ViewController。当然,这不起作用,所以我从课堂上删除了插座,认为Xcode会自动删除故事板中的引用。不幸的是,这并没有发生。我花了整整一个晚上搞清楚什么是错的。删除这些引用后,一切工作正常。而现在我感到很蠢。

相关问题