2013-08-28 33 views
1

我想從一個視圖(一個完全正常的視圖)切換到另一個視圖(也是正常的)可編程。這是我現有的代碼:如何切換到現有的非導航控制器視圖可編程?

- (IBAction)login:(id)sender { 


if([_username.text isEqualToString:name] && [_password.text isEqualToString:pw]) { 


    DashboardViewController *destinationController = [[DashboardViewController alloc] init]; 
    [self.navigationController pushViewController:destinationController animated:YES]; 

}else { 
     UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Wrong Username or Password!" 
                  message:@"Sorry." 
                 delegate:nil 
               cancelButtonTitle:@"Okay" 
               otherButtonTitles:nil, nil]; 
     [message show]; 
     _password.text = nil; 
    } 
} 

所以,我希望得到指向我DashboardViewController。如果我嘗試這個代碼,會顯示一個黑色的空白視圖。它有什麼問題?

+0

您是否有稱爲DashboardViewController.xib的xib或者DashboardViewController在loadview中創建它自己的視圖?看起來也許你沒有加載視圖。 –

+0

我正在使用故事板(無筆尖文件)。 Abdullah Shafique的回答非常有幫助! – Kitzng

回答

1

我最近有同樣的問題!下面是我使用的解決方案:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 
DashboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"id"]; 
[self.navigationController pushViewController:viewController animated:YES]; 

MainStoryboard應該是你的故事板的名稱和id應該是視圖控制器ID,您可以在故事板設置。

+0

假設他正在使用故事板 –

+0

它工作!謝謝!你無法相信我有多開心! :D – Kitzng

+0

@KITZNG你在使用[self.navigationController pushViewController:viewController animated:YES]; –

相關問題