简体   繁体   English

使用导航控制器中的默认后退按钮

[英]Use default back button in navigation controller

I don't know how to make a navigation controller use the default < button. 我不知道如何使导航控制器使用默认的<按钮。 The only way I know how to add a back button at all is to add a Bar Button Item but there I have to provide the image myself. 我唯一知道如何添加后退按钮的唯一方法是添加“ Bar Button Item但是我必须自己提供图像。 I want to use the default system back symbol, the kind that shows up with show/push segue. 我想使用默认的系统后退符号,该符号随show / push segue一起显示。 Is this possible? 这可能吗?

I'm guessing you're talking about doing this when presenting a view controller modally. 我猜想您在以模态方式呈现视图控制器时正在谈论这样做。 You can't add get the < as you would in a push segue because Apple decided to just not build it in (as far as I know). 您不能像在推送模式中那样添加get <,因为苹果决定不内置它(据我所知)。 Your best bet is to create a left bar button item with the text "<" or create your own back button and set it to that image to give your app some uniqueness! 最好的选择是创建一个带有文本“ <”的左栏按钮项,或者创建自己的后退按钮并将其设置为该图像,以使您的应用程序具有独特性!

i guess we can't use < by default. 我猜默认情况下我们不能使用<。 we need to add < image. 我们需要添加<图片。 i think you should create a class Basecontroller and inherit all classes from this. 我认为您应该创建一个类Basecontroller并从中继承所有类。 and write this code in that class, so you don't need to add < image to all controller. 并在该类中编写此代码,因此您无需向所有控制器添加<image。 just set image in only one class. 只在一个班级设置图像。

class BaseController: UIViewControlller {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back_indicator")
        self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back_indicator")
        self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.Plain, target:nil, action:nil)
    }
}

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

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