将导航栏转换为标签栏应用程序
我想知道如何将 NavigationController 风格的应用程序转换为 TabBarcontroller 风格的应用程序。我将主窗口更改为不再包含导航控制器(而是包含 tabbarcontroller),并且我的委托也相应地更改,但是当我启动应用程序时,某些东西仍然认为我想要一个导航控制器:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ setValue:forUndefinedKey:]:此类与键 navigationController 的键值编码不兼容。”
堆栈跟踪:
#0 0x020fa004 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___
#1 0x96fc0509 in objc_exception_throw
#2 0x020ee1c1 in -[NSException raise]
#3 0x000d8a78 in _NSSetUsingKeyValueSetter
#4 0x000d84c5 in -[NSObject(NSKeyValueCoding) setValue:forKey:]
#5 0x004fb4c8 in -[UIRuntimeOutletConnection connect]
#6 0x020af92f in -[NSArray makeObjectsPerformSelector:]
#7 0x004f9f7f in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:]
#8 0x004fbfcb in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:]
#9 0x0033b0a6 in -[UIApplication _loadMainNibFile]
#10 0x0034482a in -[UIApplication _runWithURL:sourceBundleID:]
#11 0x00341b88 in -[UIApplication handleEvent:withNewEvent:]
#12 0x0033d6d3 in -[UIApplication sendEvent:]
#13 0x003440b5 in _UIApplicationHandleEvent
#14 0x0265aed1 in PurpleEventCallback
#15 0x02092b80 in CFRunLoopRunSpecific
#16 0x02091c48 in CFRunLoopRunInMode
#17 0x0033be69 in -[UIApplication _run]
#18 0x00345003 in UIApplicationMain
#19 0x00002ec8 in main at main.m:14
我的委托的界面如下:
@interface CPPlayerAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
#pragma mark -
#pragma mark Window/view
@property (retain) IBOutlet UIWindow *window;
@property (retain) IBOutlet UITabBarController *tabBarController;
我的委托的实现:
@implementation CPPlayerAppDelegate
@synthesize window;
@synthesize tabBarController;
@synthesize stateController, distribution, languageManager, updateParser, soundPlayer, ticketProcessor;
#pragma mark -
#pragma mark Application lifecycle
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview: tabBarController.view];
[window makeKeyAndVisible];
}
我在哪里可以指定该应用程序是选项卡控制的应用程序,而不是导航栏控制的应用程序?
提前致谢,
I was wondering how to convert a NavigationController style app into a TabBarcontroller style app. I changed my mainwindow to not contain a navigationcontroller anymore (but a tabbarcontroller instead) and my delegate also appropriately, but when I launch the app something still thinks I want a navigationController:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navigationController.'
Stack trace:
#0 0x020fa004 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___
#1 0x96fc0509 in objc_exception_throw
#2 0x020ee1c1 in -[NSException raise]
#3 0x000d8a78 in _NSSetUsingKeyValueSetter
#4 0x000d84c5 in -[NSObject(NSKeyValueCoding) setValue:forKey:]
#5 0x004fb4c8 in -[UIRuntimeOutletConnection connect]
#6 0x020af92f in -[NSArray makeObjectsPerformSelector:]
#7 0x004f9f7f in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:]
#8 0x004fbfcb in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:]
#9 0x0033b0a6 in -[UIApplication _loadMainNibFile]
#10 0x0034482a in -[UIApplication _runWithURL:sourceBundleID:]
#11 0x00341b88 in -[UIApplication handleEvent:withNewEvent:]
#12 0x0033d6d3 in -[UIApplication sendEvent:]
#13 0x003440b5 in _UIApplicationHandleEvent
#14 0x0265aed1 in PurpleEventCallback
#15 0x02092b80 in CFRunLoopRunSpecific
#16 0x02091c48 in CFRunLoopRunInMode
#17 0x0033be69 in -[UIApplication _run]
#18 0x00345003 in UIApplicationMain
#19 0x00002ec8 in main at main.m:14
The interface for my delegate is as follows:
@interface CPPlayerAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
#pragma mark -
#pragma mark Window/view
@property (retain) IBOutlet UIWindow *window;
@property (retain) IBOutlet UITabBarController *tabBarController;
The implementation of my delegate:
@implementation CPPlayerAppDelegate
@synthesize window;
@synthesize tabBarController;
@synthesize stateController, distribution, languageManager, updateParser, soundPlayer, ticketProcessor;
#pragma mark -
#pragma mark Application lifecycle
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview: tabBarController.view];
[window makeKeyAndVisible];
}
Where can I specify the app is a tabbarcontrolled app, instead of a navigationbarcontrolled app?
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要更改您的主 XIB。在 Interface Builder 中打开它,删除当前拥有的导航控制器,并将其替换为选项卡栏控制器。然后将应用程序委托的
tabBarController
出口链接到 XIB 中的选项卡栏控制器。有关如何执行所有这些操作的更多信息,请参阅 Interface Builder 用户指南,更具体地说,连接和绑定部分。You need to alter your main XIB. Open it in Interface Builder, delete the navigation controller you've currently got, and replace it with a tab-bar controller. Then link your application delegate's
tabBarController
outlet to the tab-bar controller in the XIB. For more information about how to do all that, see the Interface Builder User Guide and, more specifically, the Connections and Bindings section.在我将项目转换为 iPad 应用程序后,我发现 -Info.plist 文件引用了错误的 xib 文件,然后删除了导航控制器并替换了一个没有它的新的顶级视图结构。我已经加载并编辑了非 iPad xib,但忽略了使用其他 xib 创建的 Resources-iPad 文件夹。
一旦照顾了那个xib,一切就都好了。
I found that the -Info.plist file had a reference to the wrong xib file after I had converted my project to an iPad app, and then removed the navigation controller and substituted a new top level view structure without it. I had loaded and edited the non-iPad xib, but had overlooked the Resources-iPad folder that had been created with the other xib.
Once took care of that xib, everything was fine.