iphone - UIImage 和 "back"按钮都出现在我的 viewController 中

标签 iphone objective-c ios uinavigationcontroller

我的 View Controller 中同时出现了一个 UIImage 和一个“后退”按钮,但我不明白为什么。

截图如下:

enter image description here

这是我的代码:

- (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];

}

感谢您的帮助。

最佳答案

您必须创建一个后退栏按钮项并向其添加自定义项。然后为其定义操作,弹出当前 View 。

 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];
}

关于iphone - UIImage 和 "back"按钮都出现在我的 viewController 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10608302/

相关文章:

iphone - 告诉 iCloud 何时没有更多待处理的核心数据更新更改

iphone - 游戏中心: seperate leaderboard for iPhone/iPad in universal app

objective-c - 如何在多个类中使用 C 风格结构

ios - 使用 iPhone Hooks 将图片/视频从照片上传到 Instagram

android - Xamarin - Navigation.PopModalAsync() 后重新加载页面

iphone - 来自 iOS 应用程序的网络钓鱼 : Possible?

iphone - iOS4:应用程序终止事件?

ios - 类中定义的方法无法识别

iphone - 在应用程序内创建的文件的pathForResource

ios - 如何以编程方式将 UINavigationController 添加到现有的 UIViewController