[英]Adding a navigation controller to a tab bar application
I have two questions about this one. 我对此有两个问题。 First, I have the navigation controller successfully put in the storyboard and is linked with the tabs and is working how I would want it to.
首先,我已将导航控制器成功放入情节提要中,并与选项卡链接,并且正在按我的意愿进行工作。 Except for one thing.
除了一件事。 When I try to add a code such as this
当我尝试添加这样的代码时
[self.navigationController popToViewController:vc animated:YES]
I get an error Property 'navigationController' not found on object of type 'AppDelegate *' [self.navigationController popToViewController:vc animated:YES]
我收到错误消息,在类型为'AppDelegate *'的对象上找不到属性'navigationController'
Is this because I put it in the wrong place? 这是因为我把它放错了地方吗? Or becasue its a tabbar application and something aint right.
或因为它是一个Tabbar应用程序和一些正确的东西。
It sounds like you're trying to make a call to your navigation controller from your AppDelegate. 听起来您正在尝试从AppDelegate调用导航控制器。 Unless you've specifically setup your AppDelegate to work with your navigation controller (it'd need to be a subclass of
UIViewController
), you'll get an error because there is no Navigation Controller on your AppDelegate class (by default). 除非您专门设置了AppDelegate以使其与导航控制器一起使用(它必须是
UIViewController
的子类),否则会出现错误,因为AppDelegate类上没有导航控制器(默认情况下)。 Therefore, when you make that call - the navigation controller can't be found. 因此,当您拨打该电话时-找不到导航控制器。 Notice how your AppDelegate is a subclass of
UIResponder
, not UIViewController
: 注意您的AppDelegate是
UIResponder
的子类,而不是UIViewController
的子类:
@interface AppDelegate : UIResponder <UIApplicationDelegate>
Instead, create and / or connect your navigation controller to a UIViewController
subclass - then you can make calls like this from your subclass: 而是创建和/或将导航控制器连接到
UIViewController
子类-然后可以从子类中进行如下调用:
[self.navigationController popToViewController:vc animated:YES];
To create and setup a Navigation Controller, follow these steps (may vary if you aren't using storyboards). 要创建和设置导航控制器,请执行以下步骤(如果您不使用故事板,则可能会有所不同)。
UINavigationController
Obj-C subclass. UINavigationController
Obj-C子类。 In the Xcode menu bar, select File > New
, or press CMD + N . File > New
,或按CMD + N。 Name your class and set its superclass as UINavigationController
: UINavigationController
: UIViewController
- as long as the navigationController
property is available. UIViewController
子类的现有类-只要navigationController
属性可用。 Custom Class
name to the name of your UIViewController
or UINavigationController
subclass: Custom Class
名称设置为您的UIViewController
或UINavigationController
子类的名称: navigationController
property, among hundreds of others relating to the View Controller. navigationController
属性,以及与视图控制器相关的数百个其他属性。 Remember that the AppDelegate is really a place for setting up your app and handling app events (ex. app closing, app backgrounding, app opening).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.