How to use InterfaceBuilder files in Xcode subprojects?

I am developing an application for the iPhone, which is a “module” of another launcher (it does not start from the iPhone’s main screen). To add this module to the launchpad, I have to delete the xcode file in the original xcode project (by creating a subproject). The subproject uses the NIB file as its view controller, and the subproject downloads the file using initWithNib:

root_view_controller = [[UINavigationController alloc] initWithRootViewController:[[LMU_IP_RootView alloc] initWithNibName:@"LMU_IP_RootView" bundle:nil]];

When I try to start the parent project, it crashes:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle [...] (loaded)' with name 'LMU_IP_RootView''

I assume that he cannot find the NIB file, because the root package is now a parent project, not a subproject. I could include NIB in the parent project and fixed the error, but did not solve my problem.

So my question is: how can I use InterfaceBuilder files in a subproject? Should I specify a package? How to specify a package related to this subproject?

Thank!

+3
source share
1 answer

When the package is equal nil, the search is performed in the main package, and not in your subproject package. I do not quite understand your application architecture, but I will try to specify the package containing the class as the package to search for:

NSBundle *classBundle = [NSBundle bundleForClass:[LMU_IP_RootView class]];
id vc = [[LMU_IP_RootView alloc] initWithNibName:nil bundle:classBundle]
root_view_controller = [[UINavigationController alloc]
                        initWithRootViewController:vc];
[vc release];

Please note that the nildefault nib name is "ClassName.nib", so a search will be performed in this case LMU_IP_RootView.nib.

, -init , . , .

0

Source: https://habr.com/ru/post/1767951/


All Articles