简体   繁体   English

iOS Storyboard,尝试添加条形按钮项作为后退按钮不出现

[英]iOS Storyboard, trying to add bar button item as back button not appearing

I created a UIViewController and I added a UIBarButtonItem to represent a back button and its not appearing when I run my app, just a blank screen. 我创建了一个UIViewController,并添加了一个UIBarButtonItem来表示后退按钮,当我运行我的应用程序时,该按钮没有出现,只是一个空白屏幕。

Here is a screen shot of my scene 这是我的场景的屏幕截图

在此处输入图片说明

and here is the list of items in my scene: 这是我场景中的项目列表:

在此处输入图片说明

I also connected the bar button item to my header file: 我也将bar按钮项连接到我的头文件:

@property (strong, nonatomic) IBOutlet UIBarButtonItem *BackButtonItem;

still not appearing 仍然没有出现

The button is appearing as you can see the item button on the lower left hand of your screen. 随即出现该按钮,您可以在屏幕的左下方看到项目按钮。

To create a custom back button I would embed a Navigation Controller inside of your View Controller. 为了创建一个自定义的后退按钮,我将在您的View Controller中嵌入一个Navigation Controller。 Then inside your .m file you can do the following, if you want a custom back button with a custom image. 然后,如果要使用带有自定义图像的自定义后退按钮,则可以在.m文件中执行以下操作。

- (void)viewDidLoad
{
    UIBarButtonItem *addCustomButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"YourImage.png"] style:UIBarButtonItemStylePlain target:self action:@selector(yourSelector:)];

    self.navigationItem.leftBarButtonItem = @[addCustomButton];

}

To add a back button in view controller through storyboard, follow the below steps:- 要通过情节提要在视图控制器中添加后退按钮,请执行以下步骤:-

  1. Drag the toolbar from side panel(object library) and drag on the top of the view controller. 从侧面板(对象库)拖动工具栏,然后在视图控制器的顶部拖动。
  2. A button named 'item' will automatically put there. 一个名为“ item”的按钮将自动放置在那里。
  3. Click on Item button, and you can change its name,image etc. 单击项目按钮,您可以更改其名称,图像等。
  4. Run the application, you will see the back button there. 运行该应用程序,您将在此处看到“后退”按钮。

Check this image, it will clear your all doubts. 检查此图像,它将清除您的所有疑问。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM