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];