2016-01-15 23 views

回答

0

基本上只有一個'sharedApplication'實例(它是一個單例),這意味着相互獨立的視圖控制器實例仍然可以與同一個數據對象進行交談。因此,您可以在您的sharedApplication委託中編寫方法,這可以有效地允許這兩個視圖控制器進行通信。有關更多信息,請參閱Apple文檔。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/

+0

請提供代碼 –

+0

@AmirKhanKhan SO不是代碼寫入服務。嘗試編寫一些代碼,當你遇到問題時回來。 –

0

您可以使用controllers.Suppose之間傳數據的SEGUE目的地視圖控制器,你必須在一個視圖控制器一個文本字段,並要在文本字段文本傳遞到另一個viewController.Then使用它可能是很有幫助。

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
TargetViewController *tvc; //Second view controller Object 
tvc = [segue destinationViewController]; 
tvc.lonetxt = fname.text; //use properties of another view using . operator 
tvc.ltwotxt = lname.text; 
tvc.lthreetxt = age.text; 
tvc.lfourtxt = college.text; 
} 
0

嘗試以下操作:

接口在AppDelegate

@interface MyAppDelegate : NSObject { 
    NSString *myString; 
} 
@property (nonatomic, retain) NSString *myString; 
... 
@end 

,並在.m文件爲App代表你可以這樣寫:

@implementation MyAppDelegate 

@synthesize myString; 
myString = some string; 

@end 

然後,在viewcontroller.m你可以取文件:

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate]; 
someString = appDelegate.myString; //..to read 
appDelegate.myString = some NSString;  //..to write 
相關問題