开发者

How to refresh navbar so that latest title is displayed?

开发者 https://www.devze.com 2023-04-11 07:47 出处:网络
In my implementation, I will change the title of the page after triggering some 开发者_如何学Pythonmethod

In my implementation, I will change the title of the page after triggering some 开发者_如何学Pythonmethod

//In viewdidload of my view controller which resides in a navigation controller
-(void)viewDidLoad
{
    self.title = @"Title A";
}


-(void)changeTitle
{
    self.title = @"Title B";
}

In the above example, after I trigger the 'changeTitle' method, I do not see my viewcontroller's title change immediately. In fact I need to push another viewcontroller onto the stack and subsequently press 'back' before I see the change to "title B".

Is there any way to refresh the navbar's title at the point where I change title?


I guess you are looking for:

UrNavController.navigationBar.topItem.title = @"bkjasdkahsdflkjadf";

You can reset it after you press a button.

You may also assign some other objects to that topitem like a segmentcontrol, or uilabel.


If you want to refresh the previous viewController's title then use

self.parent?.title = "Some Title"


Objective-C

[self.navigationItem setTitle:@"XYZ"];

Swift 4.2

self.navigationItem.title = "XYZ"
0

精彩评论

暂无评论...
验证码 换一张
取 消