使用 MonoTouch 将自定义后退按钮添加到导航栏
只是想确认这一点,因为我正在尝试单独学习 monoTouch..
我有一个使用 NavigationController.PushViewToController() 导航到的视图。在目的地视图上,我有一个导航栏。我可以在栏中添加一个按钮并使用代码推送到另一个视图(我碰巧知道“后退”在哪里),很好。
是否有现有的“后退按钮”控件?或者通过代码将现有后退按钮更改为“返回”?
在 Interface Builder 中,我可以看到 navigationItem 上有一个名为“Back”的属性。当我向其中添加文本时,我可以看到一个新的 BarButtonItem 添加到了导航栏。但是,当我导航到模拟器中的视图时,我从未看到此按钮。如果我尝试手动将项目拖到视图上,“后退”文本将被清除,并且该按钮将被视为自定义按钮。
我是否总是需要手动编码后退按钮?
Just want to confirm this, as I'm trying to learn monoTouch alone..
I have a view which I navigate to using NavigationController.PushViewToController(). On the destination view, I have a Navigation Bar. I can add a button to the bar and use code to push to another view (I happen to know where Back is), fine.
Is there a existing "back button" control? Or a way in to code to change the existing back button to say "Go back"?
In Interface Builder I can see there is a property on the navigationItem called "Back". When I add text to this I can see a new BarButtonItem added to the navigationBar. However I never see this button when I navigate to the view in the simulator. If I try to drag the item onto the view manually, the "Back" text is cleared and the button is treated like a custom button.
Do I always have to manually code the back button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认后退按钮(采用前一个控制器名称的按钮)无法自定义。但您可以隐藏它并用新按钮替换该按钮。
如果您有控制器,则可以在 viewDidLoad 方法上执行此操作。重写此方法可以确保所有元素都已设置。
UIBarButtonItem 采用一个可用于控制导航的处理程序。
在处理程序中,您可以执行以下操作:
The default back button (the one that takes the name of the previous controller) cannot be customized. But you can hide it and replace that button with a new one.
If you have a controller, you can do that on the viewDidLoad method. Overriding this method you are sure that all the elements have been set.
UIBarButtonItem takes an handler that you can use to control the navigation.
In the handler you can do this: