'NSInternalInconsistencyException',原因:'无法在包中加载 NIB:
'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:
我是初学者objective C。
我正在尝试 understand/copy Jitsi code。
在他们的AppDelegate.m中,他们做过这样的事情
ViewController *rootController = (ViewController *)self.window.rootViewController;
[jitsiMeet showSplashScreen:rootController.view];
return YES;
行:https://github.com/jitsi/jitsi-meet/blob/master/ios/app/src/AppDelegate.m#L59
这里showSplashScreen是这个
- (void)showSplashScreen:(UIView*)rootView {
[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];
}
RNSplashScreen showSplash方法是这样的
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView {
if (!loadingView) {
loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil] objectAtIndex:0];
CGRect frame = rootView.frame;
frame.origin = CGPointMake(0, 0);
loadingView.frame = frame;
}
waiting = false;
[rootView addSubview:loadingView];
}
行:https://github.com/crazycodeboy/react-native-splash-screen/blob/master/ios/RNSplashScreen.m
现在,我做了同样的事情,但他们使用的是 .xib 文件,而我使用的是故事板。
就像我的 info.plist 我有这个
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
所以盲目地复制代码,我在我的项目中使用故事板做了类似的事情,但我得到了以下错误
someMobileMobile[73326:1790521] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load
NIB in bundle: 'NSBundle
</Users/xyz/Library/Developer/CoreSimulator/Devices/1B60169F-B19B-459F-85C6-E80537C7B18B/data/Containers/Bundle/Application/5CDFA673-1009-49C3-8F7D-7F1A0C8E7F57/someMobileMobile.app>
(loaded)' with name 'LaunchScreen''
主要问题
这个错误是因为我使用的是故事板而不是 xib 吗?
次要问题
有人可以解释上面粘贴的代码片段吗?最后,(ViewController *)
是什么意思
查看以下 3 种实例化 Interface Builder 作品的方法的区别。
[NSStoryboard.mainStoryboard instantiateControllerWithIdentifier:@"youridentifier"];
NSStoryboard *launchScreen = [NSStoryboard storyboardWithName:@"LaunchScreen" bundle:NSBundle.mainBundle];
[launchScreen instantiateControllerWithIdentifier:@"yourIdentifier"];
[NSBundle.mainBundle loadNibNamed:@"SomeXibOrNib" owner:self topLevelObjects:nil];
在您的示例中,您尝试通过 NSNib
方法加载,但您显然是指 NSStoryboard
LaunchScreen.storyboard
使用您的代码,它实际上是在寻找名为“LaunchScreen.xib”或“LaunchScreen.nib”的 Nib,错误告诉您它不存在。
和你的第二个问题。
如果您的 info.plist 包含 MainStoryboard 的正确条目并且此 Storyboard 设置正确,它将实例化您的 Window以 ViewController 作为给定的 Root。
这意味着在“主要”Window 从该 Storyboard 加载 后,您可以访问其 rootViewController
属性 并在其中请求其 ViewController收费。
UI/NSViewControllers 通常免费提供相应的 NS/UIView,但由于子类控制器可能不同,因此需要进行类型转换以消除告诉您的警告。因此,要确保变量 rootController 将保存指向 ViewController 的对象的指针,该对象具有 属性 view 它被打字。
这是有效的,因为给定的 RootViewController 是类型“ViewController”并且很可能是 NS/UIViewController.
的子类
Typecasts 还表示您知道继承有效,因为您保证 view 属性 在运行时确实存在。
PS:it is always a bit confusing when chosen classnames are very simplified without any further indication which one is meant. ViewController 可以命名为“ANViewController”,当您有很多不同的 ViewController 时,这将有助于您进行更大的项目。
我是初学者objective C。
我正在尝试 understand/copy Jitsi code。
在他们的AppDelegate.m中,他们做过这样的事情
ViewController *rootController = (ViewController *)self.window.rootViewController;
[jitsiMeet showSplashScreen:rootController.view];
return YES;
行:https://github.com/jitsi/jitsi-meet/blob/master/ios/app/src/AppDelegate.m#L59
这里showSplashScreen是这个
- (void)showSplashScreen:(UIView*)rootView {
[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];
}
RNSplashScreen showSplash方法是这样的
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView {
if (!loadingView) {
loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil] objectAtIndex:0];
CGRect frame = rootView.frame;
frame.origin = CGPointMake(0, 0);
loadingView.frame = frame;
}
waiting = false;
[rootView addSubview:loadingView];
}
行:https://github.com/crazycodeboy/react-native-splash-screen/blob/master/ios/RNSplashScreen.m
现在,我做了同样的事情,但他们使用的是 .xib 文件,而我使用的是故事板。
就像我的 info.plist 我有这个
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
所以盲目地复制代码,我在我的项目中使用故事板做了类似的事情,但我得到了以下错误
someMobileMobile[73326:1790521] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/xyz/Library/Developer/CoreSimulator/Devices/1B60169F-B19B-459F-85C6-E80537C7B18B/data/Containers/Bundle/Application/5CDFA673-1009-49C3-8F7D-7F1A0C8E7F57/someMobileMobile.app> (loaded)' with name 'LaunchScreen''
主要问题
这个错误是因为我使用的是故事板而不是 xib 吗?
次要问题
有人可以解释上面粘贴的代码片段吗?最后,(ViewController *)
是什么意思
查看以下 3 种实例化 Interface Builder 作品的方法的区别。
[NSStoryboard.mainStoryboard instantiateControllerWithIdentifier:@"youridentifier"];
NSStoryboard *launchScreen = [NSStoryboard storyboardWithName:@"LaunchScreen" bundle:NSBundle.mainBundle];
[launchScreen instantiateControllerWithIdentifier:@"yourIdentifier"];
[NSBundle.mainBundle loadNibNamed:@"SomeXibOrNib" owner:self topLevelObjects:nil];
在您的示例中,您尝试通过 NSNib
方法加载,但您显然是指 NSStoryboard
LaunchScreen.storyboard
使用您的代码,它实际上是在寻找名为“LaunchScreen.xib”或“LaunchScreen.nib”的 Nib,错误告诉您它不存在。
和你的第二个问题。
如果您的 info.plist 包含 MainStoryboard 的正确条目并且此 Storyboard 设置正确,它将实例化您的 Window以 ViewController 作为给定的 Root。
这意味着在“主要”Window 从该 Storyboard 加载 后,您可以访问其 rootViewController
属性 并在其中请求其 ViewController收费。
UI/NSViewControllers 通常免费提供相应的 NS/UIView,但由于子类控制器可能不同,因此需要进行类型转换以消除告诉您的警告。因此,要确保变量 rootController 将保存指向 ViewController 的对象的指针,该对象具有 属性 view 它被打字。
这是有效的,因为给定的 RootViewController 是类型“ViewController”并且很可能是 NS/UIViewController.
Typecasts 还表示您知道继承有效,因为您保证 view 属性 在运行时确实存在。
PS:it is always a bit confusing when chosen classnames are very simplified without any further indication which one is meant. ViewController 可以命名为“ANViewController”,当您有很多不同的 ViewController 时,这将有助于您进行更大的项目。