简体   繁体   English

在视图控制器子类上添加导航控制器

[英]Adding navigation controller on a view controller subclass

How do you add a navigation controller on a newly created view controller? 如何在新创建的视图控制器上添加导航控制器? i've search everywhere but all the tutorials are from creating a navigation controller project. 我到处搜索,但所有教程都来自创建导航控制器项目。

Anyone can lead mo to a tutorial that creates a navigation controller using a view controller subclass? 任何人都可以引导mo到使用视图控制器子类创建导航控制器的教程?

What i'm doing so far: 到目前为止我在做什么:

I created a UIViewController Project, and i have something like this to go to another view controller, with a navigation controller. 我创建了一个UIViewController项目,我有这样的东西去了另一个视图控制器,带有导航控制器。

NavController *view=[[NavController alloc] initWithNibName:nil bundle:nil];
view.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:view animated:YES];
[view release];

Added a new view controller subclass. 添加了一个新的视图控制器子类。

Add > New File > UIViewController subclass with nib 使用nib添加>新文件> UIViewController子类

on NavController.h 在NavController.h上

#import <UIKit/UIKit.h>


@interface NavController : UIViewController {

    IBOutlet UIWindow *window;
    IBOutlet UINavigationController *navCon;

}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navCon;

@end

on NavController.m 在NavController.m上

#import "NavController.h"


@implementation NavController

@synthesize window,navCon;


- (void)viewDidUnload {
    [super viewDidUnload];

}

- (void)dealloc {
    [window release];
    [navCon release];
    [super dealloc];
}


@end

i already dragged a Navigation Conrtoller and a Window on my IB, and connected window to window and the Navigation Controller to navcon outlets, but whats next? 我已经在我的IB上拖动了一个导航控制器和一个窗口,并将连接的窗口连接到窗口,导航控制器连接到导航插座,但接下来是什么?

如果您正在使用故事板,请选择您的视图控制器,然后在顶部菜单中选择“编辑器”/“嵌入”/“导航控制器”。

Normally, you have to create an Navigationcontroller object inside your Appdelegate.h (like the existing window object). 通常,您必须在Appdelegate.h中创建一个Navigationcontroller对象(就像现有的窗口对象一样)。 After that you import the h.File of a ViewController into the Appdelegate.m and init it like in the following example the menuviewcontroller. 之后,您将ViewController的h.File导入Appdelegate.m并在以下示例中将其初始化为menuviewcontroller。 stackoverflow 堆栈溢出

To call another view use following lines of code, so the navigationcontroller will handle everything for you. 要调用另一个视图,请使用以下代码行,以便navigationcontroller将为您处理所有内容。

#import Viewcontroller

ViewControllerName controllerVarName = [ViewControllerName alloc] init];

[self.navigationcontroller pushViewController:_ViewControllerName animated:YES];

Inside your specific ViewController use this line to set the title the Navigationcontroller will use: 在您的特定ViewController中使用此行来设置Navigationcontroller将使用的标题:

self.title = @"titleName";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM