MonoTouch 中的按钮问题 [英] Button Questions in MonoTouch
问题描述
我正在使用 MonoTouch,我提出了三个关于按钮的问题,希望有人能帮助我.
I'm working with MonoTouch and I have come up with three questions around buttons that I'm hoping someone can help me with.
我正在尝试更改标题栏中的返回"按钮.我该怎么做呢?我看过这里发布的主题:如何更改背面的文字按钮.但是,这不起作用.我觉得我没有访问控制器属性.目前,当我尝试在 ViewDidLoad 方法中设置按钮文本时,会收到 NullReferenceException.目前,我正在尝试像这样设置文本:
I'm trying to change the "Back" button in the title bar. How do I do this? I've seen the thread posted here: How to change text on a back button. However, that doesn't work. I get the vibe that I'm not accessing the controller property. Currently, I receive a NullReferenceException when I attempt to set the button text in the ViewDidLoad method. Currently, I'm trying to set the text like such:
this.NavigationItem.BackBarButtonItem.Title = "返回";
this.NavigationItem.BackBarButtonItem.Title = "Back";
我怀疑我没有访问根控制器,但我不知道该怎么做.
I have the suspicion that I'm not accessing the root controller, but I'm not sure how to do this.
对于单独页面上的后退"按钮,我想执行自定义操作.我希望它像以前一样回去.但在此之前,我想执行一些自定义代码.我该怎么做?
For a "back" button on a separate page, I want to perform a custom action. I want it to go back like it does. But before that happens, I want to execute some custom code. How do I do this?
我需要在一段文本中创建一个看起来像超链接的东西.我该怎么做?
I need to create something that looks like a hyperlink within a paragraph of text. How do I do that?
MonoTouch 看起来很酷.然而,学习曲线比我预期的要陡峭一些.谢谢!
MonoTouch seems cool. However, the learning curve is a bit steeper than I had anticipated. Thank you!
推荐答案
对于你的第一个问题 MonoTouch 特定的答案(针对您提供的问题)效果很好.
For your first question the MonoTouch-specific answer (to the question you provided) works perfectly.
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("MyBack", UIBarButtonItemStyle.Plain, null);
确保所有答案.此代码需要在推送控制器中调用,而不是在推送控制器中调用.
Make sure to the all the answers. This code needs to be called in the pushing controller, not the controller being pushed.
更新
对于您的第二个问题,您可能注意到了一些使用 Selector
或 delegate
的重载.但是它们将不起作用用于返回按钮.
For your second question you likely noticed a few overloads that takes a Selector
or a delegate
. However they won't work for a Back button.
解决此 iOS 限制的一种方法是覆盖 ViewDidAppear
或 ViewDidDisappear
以获得类似的通知.
One way to work around this iOS limitation is to override ViewDidAppear
or ViewDidDisappear
to get similar notification.
这篇关于MonoTouch 中的按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!