我正在尝试在我的iOS应用程序中创建一个动态表,但不断收到臭名昭着的消息:
无法使用标识符CEMBurialCell对单元格进行出列 - 必须为标识符"注册一个nib或类。
以下是我的代码无效。
以下是主控制器中的一些数据。
#import "CEMBurialCell.h" // The custom cell I want to use in the tableView
@interface CEMMainViewController () <UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate>
{
UITableView *deathstoday;
}
这是viewWillAppear:
方法中的一些代码。
deathstoday = [[UITableView alloc] initWithFrame:CGRectMake(1, 370, 300, 50)];
deathstoday.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
deathstoday.delegate = self;
deathstoday.dataSource = self;
deathstoday.scrollEnabled = YES;
[self.view addSubview:deathstoday];
[self fetchfeed]; // This populates the array for the tableview
这是viewDidLoad
方法中的代码。
UINib *nib = [UINib nibWithNibName:@"CEMBurialCell" bundle:nil];
[deathstoday registerNib:nib forCellReuseIdentifier:@"CEMBurialCell"];
这是我收到错误的地方:
无法使用标识符CEMBurialCell对单元格进行出列 - 必须为标识符注册一个nib或类,或者在故事板中连接原型单元格&#39;。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CEMBurialCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"CEMBurialCell" forIndexPath:indexPath];
我在CEMBurialCell
方法中初始化了viewDidLoad
,为什么我会收到此错误?我让这个例程在一个初始化为:
self = [super initWithStyle:UITableViewStylePlain]; // in program that does work
而没有工作的程序有一个
的初始化self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; // in program that doesn't work
所以上面两行是两个程序的主要区别。我使用自定义单元格而不是UITableView
单元格,因为我需要在单元格中使用actionBlock。那么为什么第二个程序会在我的自定义单元格上出错呢?相同的自定义单元格CEMBurialCell
可在其他程序中使用。我错过了什么?
答案 0 :(得分:0)
你的问题很简单。在import ctypes
import os
sharedObjectPath = (os.getcwd() + "/" + "sharedObject.so")
test = ctypes.CDLL(sharedObjectPath)
fName = "printHello()"
test.fName
中,viewDidLoad
为deathstoday
,因此您实际上并未注册笔尖。
为什么要等到nil
才能创建表格视图?您应该在致电viewWillAppear:
之前在viewDidLoad
创建表格视图。
请务必将表格视图的框架设在registerNib:forCellReuseIdentifier:
上,以便self.view.bounds
按预期工作。