Ios 从框架加载自定义单元xib
我正在开发一个cocoa框架,为托管应用程序提供一个UINavigationController和一个UITableViewController,其中包含自定义单元格 我在导航控制器的didLoad中使用以下命令,将UIViewControllers和UIViewControllers作为根视图传递给托管应用程序:Ios 从框架加载自定义单元xib,ios,objective-c,uitableview,cocoa,dylib,Ios,Objective C,Uitableview,Cocoa,Dylib,我正在开发一个cocoa框架,为托管应用程序提供一个UINavigationController和一个UITableViewController,其中包含自定义单元格 我在导航控制器的didLoad中使用以下命令,将UIViewControllers和UIViewControllers作为根视图传递给托管应用程序: NSBundle* frameworkBundle = [NSBundle bundleForClass:[self class]]; ContactsListVC *v = [[C
NSBundle* frameworkBundle = [NSBundle bundleForClass:[self class]];
ContactsListVC *v = [[ContactsListVC alloc]
initWithNibName:@"ContactsListVC"
bundle:frameworkBundle];
[self addChildViewController: v];
但我不知道如何将自定义单元格加载到tableview中,这给了我一个错误:“无法将标识符为ContactCell的单元格出列-必须为标识符注册nib或类,或者在情节提要中连接原型单元格”。我做到了
在UITableViewController的.m中
-(void)viewDidLoad {
[super viewDidLoad];
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
UINib *nib = [UINib nibWithNibName:CONTACTCELL bundle:frameworkBundle];
[[self tableView] registerNib:nib forCellReuseIdentifier:CONTACTCELL];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CONTACTCELL forIndexPath:indexPath];
//other stuff....
return cell;
}
我成功了
在UITableViewController的.m中
-(void)viewDidLoad {
[super viewDidLoad];
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
UINib *nib = [UINib nibWithNibName:CONTACTCELL bundle:frameworkBundle];
[[self tableView] registerNib:nib forCellReuseIdentifier:CONTACTCELL];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CONTACTCELL forIndexPath:indexPath];
//other stuff....
return cell;
}