重要编辑:我发布了错误的代码,像一个白痴。我在发布错误信息时曾尝试解决此问题,而不是第一个错误。请不要听我的哑巴。创建自定义表格单元,无法访问属性
我在Xcode中创建了Facebook Feed应用程序,并且在创建表格的自定义单元格时遇到了麻烦。我试图给自定义单元格上的两个UILabel赋值,并且它给了我错误“没有可见的@interface for'JSONFeedItemCell'声明选择器'nameLabel'”。我的代码如下:
主视图控制器
- (void)viewDidLoad
{
UINib *nib = [UINib nibWithNibName:@"JSONFeedItemCell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"JSONFeedItemCell"];
... // other stuff, not relevant
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
JSONFeedItemCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"JSONFeedItemCell"];
NSDictionary *p = [[[JSONFeedItemStore sharedStore] allItems]
objectAtIndex:[indexPath row]];
[[cell nameLabel] setText:@"The Name"];
return cell;
}
Cell类
#import <Foundation/Foundation.h>
@interface JSONFeedItemCell : UITableViewCell
{
}
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@end
让我知道如果你需要任何额外的信息或代码,我会很乐意提供。
你在代码中设置nameLabel的值,因为我在这里看不到它。当你设置detailLabel的值时它也能工作吗?检查你是否已经正确地连接了你的IB连接 – AppHandwerker 2012-08-02 14:51:33
当你从tableView中出列它时,你必须将单元格转换为JSONFeedItemCell。 – 2012-08-02 15:10:38
Crud,我包含了detailLabel行而不是nameLabel行!谢谢你指出,我会改变它。我应该正确地连接到XIB集,尽管我不明白这会如何改变任何事情,因为我的错误在编译器中,据我所知,它不应该受XIB影响。 – Chance 2012-08-02 15:13:04