2014-04-10 21 views
5

Ich bin neu in iOS. Und ich möchte Navigationscontroller in meiner Anwendung verwenden, aber ich habe keine Ahnung, wie es geht. So kann mich jeder Schritt für Schritt zur Navigation in meiner Anwendung führen.UINavigationController in iOS programmatisch erstellen

+1

Googeln Sie würde helfen – Rajesh

+0

haben u in stroyborad oder xib in Ihrem Xcode verwendet –

+0

[Navigation Controller Programetically] (http: //www.idev101. com/lernen/navigation_controllers.html) [Navigation Controller in Storyboard] (http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/) –

Antwort

1
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
ImageViewController2 *dealVC = (ImageViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"ImageViewController2"]; 
[self.navigationController pushViewController:dealVC animated:YES]; 

wo ImageViewController2 einen Klassennamen

1

Sie können UINavigationController in Appdelegate erstellen und Ihren ersten Viewcontroller darauf einstellen.

2

Wenn Sie alles programmgesteuert erstellen möchten, müssen Sie dies in AppDelegate tun.

Aber wenn Sie nicht wollen, es programmatisch zu tun, dann wählen Sie einfach die Viewcontroller in der Storyboard dann Menüoptionen wählen:

Editor-> Embed In -> Navigation Controller

12

In appDelegate.h

@property (strong, nonatomic) UINavigationController *navController; 

und stellen die Delegierten UINavigationControllerDelegate und Synthetisierung Objekt in appDelegate.m , jetzt

appDelegate.m

Sie Navigation-Controller in didFinishLaunchingWithOptions Methode

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    frstVwCntlr = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil]; 
    self.navController = [[UINavigationController alloc] initWithRootViewController:self.frstVwCntlr]; 
    self.window.rootViewController = self.navController; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

In dem obigen Code, Ihre firstViewController zu UINavigationController und UINavigationController hinzugefügt UIWindow wie

self.window.rootViewController = self.navController

gesetzt einstellen

Hoffe, das kann Ihnen helfen

+0

Wenn es wertvoll ist für Sie als Bitte wie die Antwort @ user3418619 – Sanawaj

1

So erstellen Sie einen UINavigationController programmatisch ohne Verwendung von Storyboards, zu Ihrem App-Delegaten gehen und folgendermaßen vorgehen. Erstellen Sie zwei Eigenschaften, Fenster und Viewcontroller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.backgroundColor=[UIColor clearColor]; 

    self.viewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]; 
    UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:self.viewController]; 
    self.window.rootViewController = navController; 
    [self.window makeKeyAndVisible]; 

    // Override point for customization after application launch. 
    return YES; 
} 
0

Hier ist der Code, den Sie in AppDelegate schreiben soll.

UIViewController *vc=[[UIViewController alloc]initWithNibName:@"vc1" bundle:nil]; 
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)]; 
view.backgroundColor=[UIColor redColor]; 
[vc setView:view]; 

self.navme=[[UINavigationController alloc]initWithRootViewController:vc]; 
self.window.rootViewController = self.navme; 
0

für Swift 3.0 mit Filter:

let desiredController = self.navigationController!.viewControllers.filter { $0 is YourController }.first! 
self.navigationController!.popToViewController(desiredController, animated: true) 
Verwandte Themen