You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Objective-C导航栏左侧按钮不显示<箭头,无需图片实现求助

Fixing the Navigation Bar Back Arrow Issue in Objective-C

Hey Diego, I’ve run into this exact problem before—let’s get that back arrow showing without needing any extra image assets! Here’s what’s going on and how to fix it:

Why the Arrow Isn’t Showing Now

When you push a new view controller onto a navigation stack, iOS automatically adds a back button with the < arrow to the new controller’s nav bar. But when you manually set leftBarButtonItem, you’re overriding that default system button—so you only see your custom text, no arrow.

And the reason setting backBarButtonItem didn’t work? That property belongs to the previous view controller (the one you pushed from), not the current one. If you set it on the current controller, it’ll only affect the next controller you push, not the current screen.

This is the simplest approach, since it leverages iOS’s built-in styling and automatic pop behavior. Just add this code to the view controller that pushes your current screen:

// In the view controller you're pushing FROM
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];

When you push to your current controller, iOS will automatically display a back button with the < arrow and your "Back" text. Plus, tapping it will pop the navigation stack automatically—you won’t even need your returnToPreviousScreen method unless you need custom behavior.

Solution 2: Manually Create a Button with the System Arrow

If you need to keep your custom returnToPreviousScreen action, you can build a button using iOS’s built-in back arrow image. Here’s how:

// Get the system's back arrow image (no extra assets needed)
UIImage *backArrowImage = [UIImage imageNamed:@"UINavigationBarBackIndicator"];

// Create a button that combines the arrow and text
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 44)];
[backButton setImage:backArrowImage forState:UIControlStateNormal];
[backButton setTitle:@"Back" forState:UIControlStateNormal];
[backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 0)]; // Add space between arrow and text
[backButton setTitleColor:self.navigationController.navigationBar.tintColor forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(returnToPreviousScreen) forControlEvents:UIControlEventTouchUpInside];

// Wrap the button in a UIBarButtonItem
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

This gives you the custom action you need while keeping the system’s native arrow.

Quick Note

UINavigationBarBackIndicator is a public system image (available in iOS 13+), so it’s safe to use. If you need to support older iOS versions, you can also fetch the arrow via [[UINavigationBar appearance] backIndicatorImage].

内容的提问来源于stack exchange,提问作者Diego Rivera

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:28:33