如何在某些情况下设置具有标题视图的导航项的标题

How to set title of navigationitem which have titleview for some conditions

我有一个 navigationItem 和一个 titleView。现在在某些情况下,我想为 navigationItem 使用 title 属性。怎么做?有什么想法吗?

这是我尝试过的方法,但是没有用:

self.revealViewController().navigationItem.titleView = UIView.init()

self.revealViewController().navigationItem.title = "My Item"

在 viewcontroller 的 viewdidload 中,您可以将标题设置为

  self.title = "your title"

在设置title之前,需要将titleView设置为nil。

UIView* titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
//titleView.backgroundColor=[UIColor redColor];

self.navigationItem.titleView=titleView;