iOS アプリにナビゲーション コントローラーを追加する方法がわかりません。「ホーム」画面以外のすべてのビューに戻るボタンが必要ですが、追加する方法がわかりません。
ここに私のプロジェクトへのリンクがあります: https://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom%204.zip
iOS アプリにナビゲーション コントローラーを追加する方法がわかりません。「ホーム」画面以外のすべてのビューに戻るボタンが必要ですが、追加する方法がわかりません。
ここに私のプロジェクトへのリンクがあります: https://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom%204.zip
すべての NIB からナビゲーション バーを削除し、ナビゲーション コントローラー (NeverBe のようなアプリ デリゲートなど) を使用してから、現在行っている方法pushViewController
ではなく、を介して子コントローラーに移行しpresentViewController
ます。戻る」ボタンが自動的に表示されます。dismissViewControllerAnimated
また、 への参照がある場合は削除する必要があります。これは、戻るボタンでできるようになっpopViewControllerAnimated
たためです。ただし、プログラムで任意の場所にポップする必要がある場合は、popViewControllerAnimated
.
NIB では、シミュレートされたメトリックを微調整して、グラフィカルに表示されたナビゲーション バーを使用して NIB を設計できるようにすることもできます。次に例を示します。
View Controller Catalogの Navigation Controller セクションを参照し、UINavigationController
Class Referenceを参照してください。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil]];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
新しいViewControllerを呼び出す
KFBYouTubeView *youtubeView = [[KFBYouTubeView alloc] initWithNibName:@"KFBYouTubeView" bundle:nil];
[self.navigationController pushViewController:youtubeView animated:YES];
アップデート:
カスタムナビゲーションバーボタンを追加する方法
- (void)customizeNavigationButtonWithType:(NavigationBarButtonType)type
normalImageName:(NSString *)normalImageName
selectedImageName:(NSString *)selectedImageName
selector:(SEL)selector {
UIImage *img = [UIImage imageNamed:normalImageName];
UIImage *imgPressed = [UIImage imageNamed:selectedImageName];
UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[customButton setImage:img forState:UIControlStateNormal];
[customButton setImage:imgPressed forState:UIControlStateHighlighted];
customButton.frame = CGRectMake(0, 0, img.size.width, img.size.height);
[customButton addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:customButton];
switch (type) {
case NavigationBarButtonTypeLeft:
[self.navigationItem setLeftBarButtonItem:btn animated:YES];
break;
case NavigationBarButtonTypeRight:
[self.navigationItem setRightBarButtonItem:btn animated:YES];
break;
}
}
使用法:
[self customizeNavigationButtonWithType:NavigationBarButtonTypeRight
normalImageName:@"create.png"
selectedImageName:@"create_highlight.png"
selector:@selector(pressButton:)];