簡體   English   中英

視圖控制器沒有被推送到堆棧

[英]Viewcontroller not getting pushed to stack

我對 iPhone 相當陌生。 我有一個奇怪的問題。 我正在添加一個視圖控制器作為當前視圖的子視圖。 然后我想從中推送一個新的視圖控制器。 問題是當我嘗試執行 pushViewController 時,它沒有響應。

例如,在 CurrentViewController 中,我添加了 NewViewController 的視圖作為 subView

[self.view addSubView : NewViewController.view]

現在從 NewViewController,單擊一個按鈕,我正在執行以下操作:

SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];

這里 secondVC 不會被推入堆棧。

如果您使用過基於視圖的應用程序,則必須使用此代碼。

  SecondViewController *secondVC = [SecondViewController   alloc]initWithNibName:@"SecondViewController" bundle:nil];
   // [self.navigationController pushViewController:secondVC animated:YES];

      [self presentModalViewController:secondVC animated:YES];

如果你想在你的應用程序中使用導航控制器。 首先,您必須在 appln 中添加導航控制器,然后才能導航視圖。

也許問題在於該方法被稱為pushViewController而不是pushToViewController 嘗試

SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM