0

ビューコントローラーに UIImage と「戻る」ボタンの両方が表示されていますが、その理由がわかりません。

ここにスクリーンショットがあります:

ここに画像の説明を入力

ここに私のコードがあります:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:YES];

    UIImage *image = [UIImage imageNamed:@"arrow_back.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    [self.navigationController.navigationBar addSubview:imageView];

}

助けてくれてありがとう。

4

3 に答える 3

2

バックバーボタンアイテムを作成し、それにカスタムを追加する必要があります。次に、そのアクションを定義し、現在のビューをポップします。

 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:buttonImage forState:UIControlStateNormal];

        //set the frame of the button to the size of the image (see note below)
        button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

        //create a UIBarButtonItem with the button as a custom view
        UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        self.navigationItem.leftBarButtonItem = customBarItem;


// selector for backButton

-(void)back{
[self.navigationController popViewController];
}
于 2012-05-15T20:36:03.420 に答える
0

カスタム ボタンを作成し、それを self.navigationController.navigationBar.backBarButtonItem のサブビューとして追加する必要があります。

于 2012-05-15T20:27:54.323 に答える
0

2 つ目のビュー コントローラーをナビゲーション コントローラーにプッシュすると、[戻る] ボタンが自動的に表示されます。Andrew Eblingが述べたように、それをオーバーライドできます。カスタム UIBarButton アイテムを作成する必要があります。

UIImage *image = [UIImage imageNamed:@"back.png"];
UIBarButtonItem *back = [UIBarButtonItem alloc] initWithImage:image
                                                        style:UIBarButtonItemStylePlain
                                                       target:self
                                                       action:@selector(backEvent:)];

self.navigationItem.backBarButtonItem = back;
于 2012-05-15T20:31:07.027 に答える