[英]iOS Navigation Bar Title set dinamically is making a ellipsis in text when view appears
I was trying to set the back button title in a navigation bar, like this 我试图在导航栏中设置后退按钮标题,就像这样
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.title = self.backUpTitle
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.title = "Back"
}
Where self.backUpTitle
has the original title for the current ViewController. 其中self.backUpTitle
具有当前ViewController的原始标题。
It works very well, but I'm a having a quick effect each time I click "Back": the title of the navigation bar appears with the first three letters followed by ellipsis (Eg: "Title" would show as "Tit..."), and after the view fully appears, it shows the entire title without any problem. 效果很好,但是每次单击“上一步”时我都会很快见效:导航栏的标题出现,前三个字母后接省略号(例如:“标题”将显示为“山雀”。 ”),然后在完全显示该视图后,它会显示整个标题,没有任何问题。
The thing is... it does not happen in a normal case, so I guess it has to do with my solution about setting Back Button Title. 问题是...在正常情况下不会发生,因此我想这与我设置后退按钮标题的解决方案有关。
The question is: is there a way to avoid this effect? 问题是: 有没有办法避免这种影响? Am I calling self.title
in a wrong function? 我在错误的函数中调用self.title
吗?
I'm using Xcode 8 and iOS 10.0 我正在使用Xcode 8和iOS 10.0
I've tried running your code on my own machine and I'm not showing the same problem; 我尝试在自己的计算机上运行您的代码,但没有显示相同的问题; I'm thinking you might be using custom views for the title of the navigation bar and your self.backUpTitle is inside a custom view that causes the ellipsis. 我认为您可能正在使用自定义视图作为导航栏的标题,而您的self.backUpTitle位于导致省略号的自定义视图内部。
Some suggestions: 一些建议:
If you just want to show “Create User” that way without the ellipsis, you might want to remove all custom views for your navigation bar and just set the ViewController title like what you are doing in your code. 如果只想以这种方式显示“创建用户”而不用省略号,则可能要删除导航栏的所有自定义视图,并像在代码中一样设置ViewController标题。
Using “self.title” will change the title of your ViewController, make sure your ViewController is embedded to a UIViewController. 使用“ self.title”将更改您的ViewController的标题,请确保将ViewController嵌入到UIViewController中。 However, if you created your navigation bar, setting the title should be: 但是,如果您创建了导航栏,则将标题设置为:
navigationBar.topItem.title = “Create User”
Just to reiterate, this is what my code looks like (which looks like yours) under a ViewController that is embedded in a UINavigationController: 重申一下,这是我的代码在UINavigationController中嵌入的ViewController下的样子(看起来像您的样子):
var backUpTitle: String! override func viewDidLoad() { backUpTitle = "Create User" } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.title = self.backUpTitle } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) self.title = "Back" }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.