简体   繁体   中英

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.

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:

@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. Then inside your .m file you can do the following, if you want a custom back button with a custom image.

- (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.
  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. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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