Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从框架加载自定义单元xib_Ios_Objective C_Uitableview_Cocoa_Dylib - Fatal编程技术网

Ios 从框架加载自定义单元xib

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

我正在开发一个cocoa框架,为托管应用程序提供一个UINavigationController和一个UITableViewController,其中包含自定义单元格

我在导航控制器的didLoad中使用以下命令,将UIViewControllers和UIViewControllers作为根视图传递给托管应用程序:

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;
    }