1
我在RootViewController中設置了splitViewController中的userName標籤文本,它工作正常,但問題是我想更改otherViewController中的userName標籤文本,但是當我打開Root Viewcontroller時,它沒有得到新的userName可能是由於它不會重新加載。如何重新加載rootViewController在另一個ViewController在ipad
我在RootViewController中設置了splitViewController中的userName標籤文本,它工作正常,但問題是我想更改otherViewController中的userName標籤文本,但是當我打開Root Viewcontroller時,它沒有得到新的userName可能是由於它不會重新加載。如何重新加載rootViewController在另一個ViewController在ipad
首先,您需要設置一個全局變量來訪問此處,您可以從另一個類設置用戶名,然後可以使用波紋管方法設置特定變量的用戶名。
可以從其他類使用@protocol
或
您可以使用NSNotificationCenter
作爲婁
添加婁方法到您rootViewcontroller
ViewDidLoad
方法訪問類方法: -
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(actionNotificationData:)
name:@"reloadData"
object:nil];
-(void)actionNotificationData:(NSNotification *)notification {
//your code for variable logic
}
and p UT婁方法調用,其中從要NSNotificationCenter
調用reloadData rootViewcontroller
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
的
可能重複[我如何建立一個簡單的委託兩種顯示控制器之間的溝通?(http://stackoverflow.com/questions/6168919 /如何-DO-I-建立-A-簡單代表對通信二間 - 視圖 - 控制器) – Tariq