ルートとして設定されているナビゲーションコントローラー()UIViewController
に(AddProjectViewController)を追加しようとしていますが、機能しません。navigationController
tableView
これが私がファイルをセットアップする方法です:http://d.pr/y8rt
コードはにありますProjectsController.m
-助けてください:(
ルートとして設定されているナビゲーションコントローラー()UIViewController
に(AddProjectViewController)を追加しようとしていますが、機能しません。navigationController
tableView
これが私がファイルをセットアップする方法です:http://d.pr/y8rt
コードはにありますProjectsController.m
-助けてください:(
わかりましたので、最初に何が間違っているのかを説明します。
// You're not allocating the view here.
AddProjectViewController *nextController = addProjectViewController;
// When allocated correctly above, you can simple push the new controller into view
[self.navigationController pushViewController: (UIViewController *)addProjectViewController animated:YES];
プッシュされたビュー コントローラーは、スーパー (それをプッシュしているビュー コントローラー) のナビゲーション バーを自動的に継承します (つまり、子ビュー コントローラーで self.navigationController を呼び出すことができます。これは、UINavigationController が単に UIViewController のサブクラスであるためです (また、UITableViewController も同様です)。
必要な作業は次のとおりです。
// Allocate AddProjectViewController
AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] init];
// Adds the above view controller to the stack and pushes it into view
[self.navigationController pushViewController:addProjectViewController animated:YES];
// We can release it again, because it's retained (and autoreleases in the stack). You can also choose to autorelease it when you allocate it in the first line of code, but make sure you don't call release on it then!
[addProjectViewController release];
ただし、あなたがやろうとしていることについては、ビュー コントローラーをモーダルに表示する方がはるかに優れています。つまり、ナビゲーション コントローラー内に保持する必要があります。方法は次のとおりです。
// Allocate AddProjectViewController
AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] init];
// Create a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addProjectViewController];
// Release the view controller that's now being retained by the navigation controller
[addProjectViewController release];
// Adds the above view controller to the stack and present it modally (slide from bottom)
[self presentModalViewController:navigationController animated:YES];
// Release the navigation controller since it's being retained in the navigation stack
[navigationController release];
AddProjectViewController クラスで UIBarButtonItems を作成する必要があることに注意してください。
コードを更新し、ここにアップロードしました: http://dl.dropbox.com/u/5445727/Zum.zip
ここでコメントを確認する必要があります。私はそれらをあなたのプロジェクトに転送しませんでした。幸運を :)