I'm using custom titleView for navigation bar in viewDidLoad, here is my code:

UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 220, 44)];
titleView.text = @"Hello";
titleView.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = titleView;

But I want to change this title text later programmatically, I tried couple ways with no success.

self.navigationItem.titleView.text = @"Loading...";
self.navigationItem.title = @"Loading...";

How do I change the title text in custom titleView ?

没有正确的解决方案

其他提示

If the initial code works you should allocate a new label, set its text and reset it and that should probably work.

Alternatively store the label as a property and try setting its title from self.label.text = @"..."

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top