问题描述
我正在splitViewController的RootViewController中设置userName标签文本,它可以正常工作,但问题是我想在otherViewController中更改userName标签文本,但是当我打开Root Viewcontroller时,它没有得到新的userName可能是由于它不会重新加载.
首先,您需要设置一个全局变量以访问该变量,在此变量中您可以从另一个类中设置Username,然后可以使用以下方法在特定变量上设置Username./p>
您可以使用从其他类访问类方法@protocol
或
您可以将 NSNotificationCenter
用作波纹管
将贝娄方法添加到您的 rootViewcontroller
ViewDidLoad
方法中:-
[[NSNotificationCenter defaultCenter] addObserver:self选择器:@选择器(actionNotificationData :)名称:@"reloadData"对象:无];-(void)actionNotificationData:(NSNotification *)notification {//您的可变逻辑代码}
并放置Bellow方法以调用 NSNotificationCenter
,从此处要调用reloadData rootViewcontroller
[[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
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.
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];
这篇关于如何在ipad中的另一个ViewController中重新加载rootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!