2013-04-25 128 views
0

我試圖從一個視圖導航到另一個觸摸按鈕使用iOS 5.0。iOS無法加載視圖

我使用

- (IBAction)Actionlogin:(id)sender { 
    NSLog(@" login button has been pressed"); 
     NSLog(@"In init"); 
     test_details *aSecondPageController=[[test_details alloc]initWithNibName:@"test_details" bundle:nil]; 
     [self.navigationController pushViewController:aSecondPageController animated:NO]; 
     } 

的代碼,我有兩個XIB文件test_details_iPhone.xibtest_details_iPad.xib

裏面我testdetails.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    NSLog(@"it is coming here in second view"); 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 

    if (self) { 
     // Custom initialization 
    } 
    NSLog(@"it has been returned "); 
    return self; 


} 

日誌

2013-04-25 11:06:17.191 app_gototest[3067:207] login button has been pressed 
2013-04-25 11:06:17.194 app_gototest[3067:207] In init 
2013-04-25 11:06:17.195 app_gototest[3067:207] it is coming here in second view 
2013-04-25 11:06:17.196 app_gototest[3067:207] it has been returned 

視圖不會被加載到視圖上。我想我錯過了一些東西。

應用中:didFinishLaunchingWithOptions:appDelegate

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

**我想碧玉藍的方法**

argc int 1 
argv char ** 0xbfffed2c 
*argv char * 0xbfffee44 

在appDeleagte.m

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

你想從iPhone的廈門國際銀行轉移到iPad的廈門國際銀行? – 2013-04-25 05:46:43

+0

號碼。 我正在爲iPhone和iPad編寫應用程序。 from iPhone 1st view to iPhone second from iPad 1st view to iPad second – onkar 2013-04-25 05:47:56

+0

@onkar:我可以知道你的應用程序的模板類型嗎?它是基於導航還是基於Tab? – 2013-04-25 05:49:27

回答

2

你的代碼看起來不錯,所以它必須是self.navigationController是零。 。 。你有沒有設置導航控制器?

爲了您的代碼正常工作,您當前的UIViewController需要包含在UINavigationController中。 。 。您可以設置的UINavigationController在您的應用程序委託的根視圖控制器如下:

{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    UINavigationController* navigationController; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone"  bundle:nil]; 
    navigationController = [UINavigationController alloc]   initWithRootViewController:viewController]; 
    } else { 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad"  bundle:nil]; 
     navigationController = [UINavigationController alloc] initWithRootViewController:viewController]; 
    } 
    self.window.rootViewController = navigationController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

注意:您可以清理上面的代碼了一點,但你得到的圖片,這是你必須設置根視圖控制器是一個導航控制器,就像這樣:

self.window.rootViewController = navigationController; 

你也可以做一個自定義的根視圖控制器,如果你喜歡,但是上面會讓你達到你想要做什麼 - UINavigationController將在整個應用程序中用作導航系統。

+0

我不這麼認爲....請你能指導我嗎? – onkar 2013-04-25 06:01:40

+0

如上所示設置導航控制器。 。 。爲了證明你的self.navigationController是nil,試試NSLog(@「My nav controller%@」,self.navigationController); ;) – 2013-04-25 06:05:09

+0

該代碼已經存在。請檢查問題.. – onkar 2013-04-25 06:06:55

0

您的導航控制器爲零。因此,與

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
    } else { 
     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; 
    } 
    UINavigationController *navcontroller = navigationController = [UINavigationController alloc] initWithRootViewController:self.viewController]; 
    self.window.rootViewController = navcontroller; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

現在你有一個導航控制器更換您的didFinishLaunchingWithOptions方法,以便調用上推self.navigationController方法應推動第二控制器。

0

請嘗試

- (IBAction)Actionlogin:(id)sender { 
    NSLog(@" login button has been pressed"); 
    NSLog(@"In init"); 
    test_details *aSecondPageController=[[test_details alloc]initWithNibName:@"test_details_iPhone" bunndle:nil]; 
    [self.navigationController pushViewController:aSecondPageController animated:NO]; 
    } 

// test_details_iPhone.xib and test_details_iPad.xib 
//Change [email protected]"test_details" with test_details_iPhone or test_details_iPad 
+0

iPhone和iPad都不起作用 – onkar 2013-04-25 06:34:48