What I mean is a static "top-bar" that I can edit from the relevant swift file.
我的意思是一个静态的“顶栏”,我可以从相关的swift文件编辑。
I don't actually want any of the navigation function, but I want to be able to change what it says situationally.
我实际上并不想要任何导航功能,但我希望能够改变它的情境。
I've looked around quite a bit but can't seem to find a solution for this seemingly simple task.
我看了很多,但似乎无法找到这个看似简单的任务的解决方案。
Thanks in advance.
提前致谢。
3 个解决方案
#1
I am not quite sure, if this is what you want. However, if you want a navigation bar with customizable navigation item title/text, then you can just add Navigation Item from the Object library to your Navigation bar.
我不太确定,如果这是你想要的。但是,如果您想要一个带有可自定义导航项标题/文本的导航栏,则只需将对象库中的导航项添加到导航栏即可。
Then in the inspector, you can select custom and specify the title of that navigation item as you desire. You can also create an IBOutlet for it and change the title in your code in different situations.
然后在检查器中,您可以选择自定义并根据需要指定该导航项的标题。您还可以为其创建IBOutlet,并在不同情况下更改代码中的标题。
#2
Ctrl Drag the bar button from the storyboard to the appropriate view controller implementation file. I.e viewController.h. This will create an IBAction, which you can name.
Ctrl将条形图按钮从故事板拖动到相应的视图控制器实现文件。即viewController.h。这将创建一个IBAction,您可以命名。
- (IBAction)nameOfAction:(id)sender {
// Action goes here
}
Any logic applied inside will be called on button press.
内部应用的任何逻辑都将在按下按钮时调用。
#3
So it was a pretty easy, but not straightforward solution...
所以这是一个非常简单但不简单的解决方案......
All I had to do was
我所要做的就是
- Add a navigation bar, by clicking Editor -> Embed in -> Navigation Controller
- The hard to find part, use the property
self.navigationItem.title = "title"
to change the title.
单击编辑器 - >嵌入 - >导航控制器,添加导航栏
难以找到的部分,使用属性self.navigationItem.title =“title”来更改标题。
The second part I found from hgwhittle's answer in this question, which also covers how to change the nav bar title, the tab bar title, or both.
第二部分我从hgwhittle的回答中找到了这个问题,其中还介绍了如何更改导航栏标题,标签栏标题或两者。
UIViewController Title attribute in Storyboard
故事板中的UIViewController标题属性
#1
I am not quite sure, if this is what you want. However, if you want a navigation bar with customizable navigation item title/text, then you can just add Navigation Item from the Object library to your Navigation bar.
我不太确定,如果这是你想要的。但是,如果您想要一个带有可自定义导航项标题/文本的导航栏,则只需将对象库中的导航项添加到导航栏即可。
Then in the inspector, you can select custom and specify the title of that navigation item as you desire. You can also create an IBOutlet for it and change the title in your code in different situations.
然后在检查器中,您可以选择自定义并根据需要指定该导航项的标题。您还可以为其创建IBOutlet,并在不同情况下更改代码中的标题。
#2
Ctrl Drag the bar button from the storyboard to the appropriate view controller implementation file. I.e viewController.h. This will create an IBAction, which you can name.
Ctrl将条形图按钮从故事板拖动到相应的视图控制器实现文件。即viewController.h。这将创建一个IBAction,您可以命名。
- (IBAction)nameOfAction:(id)sender {
// Action goes here
}
Any logic applied inside will be called on button press.
内部应用的任何逻辑都将在按下按钮时调用。
#3
So it was a pretty easy, but not straightforward solution...
所以这是一个非常简单但不简单的解决方案......
All I had to do was
我所要做的就是
- Add a navigation bar, by clicking Editor -> Embed in -> Navigation Controller
- The hard to find part, use the property
self.navigationItem.title = "title"
to change the title.
单击编辑器 - >嵌入 - >导航控制器,添加导航栏
难以找到的部分,使用属性self.navigationItem.title =“title”来更改标题。
The second part I found from hgwhittle's answer in this question, which also covers how to change the nav bar title, the tab bar title, or both.
第二部分我从hgwhittle的回答中找到了这个问题,其中还介绍了如何更改导航栏标题,标签栏标题或两者。
UIViewController Title attribute in Storyboard
故事板中的UIViewController标题属性