2011-12-22 38 views

Trả lời

5

Trừ khi bạn thêm UINavigationController vào UIViewController khác được sử dụng cho một phương pháp điều hướng khác, tức là UISplitViewController hoặc UITabBarController, tôi khuyên bạn nên thêm UINavigationController vào cửa sổ ứng dụng của bạn trong AppDelegate sau đó thêm UIViewController có chế độ xem của bạn nó.

Nếu bạn đang thêm UINavigationController như UIViewController chính của bạn, bạn có thể dễ dàng làm được điều này lập trình bằng phương pháp sau trong appdelegate:

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

Code tôi sẽ thêm là:

UINavigationController *navcon = [[UINavigationController alloc] init]; 
[navcon pushViewController:self.viewController animated:NO]; 
self.window.rootViewController = navcon; 

Bây giờ, trong AppDelegate.m của bạn sẽ trông giống như sau:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; 
    } 
    else 
    { 
     self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; 
    } 
    UINavigationController *navcon = [[UINavigationController alloc] init]; 
    [navcon pushViewController:self.viewController animated:NO]; 
    self.window.rootViewController = navcon; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

Bạn có thể tìm hiểu thêm về cách sử dụng UINavigationController bằng cách xem UINavigationController Apple Documentation và các dự án ví dụ của chúng, mà bạn có thể tải xuống từ cùng một trang tài liệu. Các dự án ví dụ sẽ giúp bạn nắm được các cách khác nhau mà bạn có thể sử dụng UINavigationController.

+0

cảm ơn !!!!!!!!!!!!!!! – CrazyDev

0

Bạn phải tạo UINavigationController lớp trong dự án của mình và đính kèm theo nghĩa là lớp IBOutLet UINavigationController trong lớp application delegate và xác định lớp đó trong lớp đại biểu của bạn. Trong số Interface Builder, hãy kết nối IBOutLet với lớp đại biểu.

Các vấn đề liên quan