2012-08-22 23 views
1

我想在我的TabBarController視圖加載之前啓動初始登錄/註冊屏幕。我已經讀過,在第一視圖中放置ModalViewController是一個好方法。這工作,但我想添加導航控件到ModalViewController。我得到了以下問題:iPhone ModalViewController從第一個標籤欄視圖

1 - 錯誤:屬性 'navigationController' 不是類型的對象發現 '的AppDelegate'

2 - WARNING:初始化 '的AppDelegate *' 不兼容類型的表達式'ID'

這裏是我的ModalViewController代碼:

-(IBAction)signUpButtonTapped { 
// i need to get the control for main navigation controller 
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; 
[appDelegate.navigationController popToRootViewControllerAnimated:NO]; 
// create object from app main view to push it 
SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil]; 
[AppDelegate.navigationController pushViewController:signUpViewController animated:YES]; } 

人有什麼想法?非常感謝!

+0

類型轉換與AppDelegate中'(* AppDelegate中)'將解決警告 –

+0

看看我的答案,它也會解決你的錯誤 –

回答

2

有在你的代碼

1)訪問與類名稱的對象的兩個問題。它必須是appDelegate.nav ...(小a解決1個ERROR)

[appDelegate.navigationController pushViewController:signUpViewController animated:YES]; 

2)類型轉換的賦值(解決2警告)

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 

所以你完整的工作守則必須爲

-(IBAction)signUpButtonTapped { 
    // i need to get the control for main navigation controller 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 
    [appDelegate.navigationController popToRootViewControllerAnimated:NO]; 
    // create object from app main view to push it 
    SignUpViewController *signUpViewController = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil]; 
    [appDelegate.navigationController pushViewController:signUpViewController animated:YES]; 
} 
0

在你的代碼修改此行

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; 

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

現在嘗試

+0

優秀,這擺脫了我的警告,但我仍然得到錯誤:屬性'導航控制器'找不到類型'AppDelegate'的對象。我已經宣佈它,但它一直顯示這個錯誤。有任何想法嗎?謝謝! – Brandon

+0

您是否聲明瞭Appdelegate中的Navigationcontroller屬性 –

0

的AppDelegate實例聲明是這樣的:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate]; 

改變這一點,烏爾走去吧。

+0

非常好,即擺脫了我的警告,但我仍然收到錯誤:Property'navigationController'找不到'AppDelegate'類型的對象。我已經宣佈它,但它一直顯示這個錯誤。有任何想法嗎?謝謝! – Brandon

0

1.確保你的appDelegate有UINavigationController屬性調用navigationController 。你的代碼的 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

3.last線: [appDelegate.navigat....
NOT:

2.Line代碼的2
[AppDelegate.navigatio....

+0

也是正確的答案。謝謝! – Brandon

相關問題