how to reload the rootViewController in another Vi

2019-08-13 07:34发布

问题:

I am setting the userName label text in RootViewController in splitViewController it works fine but problem is that I want to change the userName label text in otherViewController but when I open Root Viewcontroller it does not get the new userName may be due to it does not get reloaded again.

回答1:

First you need to set one global variable for accessing this where you set Username from another class and then you can use bellow methods for set Username on particular variable.

you can access class method from Other class using @protocol

or

You can use NSNotificationCenter as Bellow

Add Bellow Method into your rootViewcontroller ViewDidLoad method:-

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(actionNotificationData:)
                                                 name:@"reloadData"
                                               object:nil];

-(void)actionNotificationData:(NSNotification *)notification {

   //your code for variable logic

}

and put Bellow Method for calling NSNotificationCenter where from you want to calling reloadData rootViewcontroller

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];