0

iOS アプリにナビゲーション コントローラーを追加する方法がわかりません。「ホーム」画面以外のすべてのビューに戻るボタンが必要ですが、追加する方法がわかりません。

ここに私のプロジェクトへのリンクがあります: https://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom%204.zip

4

2 に答える 2

1

すべての NIB からナビゲーション バーを削除し、ナビゲーション コントローラー (NeverBe のようなアプリ デリゲートなど) を使用してから、現在行っている方法pushViewControllerではなく、を介して子コントローラーに移行しpresentViewControllerます。戻る」ボタンが自動的に表示されます。dismissViewControllerAnimatedまた、 への参照がある場合は削除する必要があります。これは、戻るボタンでできるようになっpopViewControllerAnimatedたためです。ただし、プログラムで任意の場所にポップする必要がある場合は、popViewControllerAnimated.

NIB では、シミュレートされたメトリックを微調整して、グラフィカルに表示されたナビゲーション バーを使用して NIB を設計できるようにすることもできます。次に例を示します。

ナビゲーション バーのシミュレートされた指標

View Controller Catalogの Navigation Controller セクションを参照し、UINavigationControllerClass Referenceを参照してください。

于 2012-11-05T14:54:47.160 に答える
0
- (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:)];
于 2012-11-05T14:57:50.730 に答える