2013-05-03 46 views
0

我有臨時變量eneity和兩個視圖控制器:OneViewControllerSecondViewController。他們跳到對方fine.now使用eneityOneViewController值發送到SecondViewController。但是,當SecondViewController返回值爲eneity時,OneViewController無法再獲取返回值。是可以使用臨時變量通價值

我想知道如果我可以使用變量來獲得返回值,而不是委託?

感謝您的幫助;

ADD:

firstViewController,Example3ViewController

#import "Example3ViewController.h" 

@interface Example3ViewController() 

@end 

@implementation Example3ViewController 
@synthesize editorVC; 
@synthesize labelname; 
@synthesize labelnumber; 
@synthesize labelsummary; 
@synthesize b; 

(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
// Custom initialization 
} 
return self; 
} 

(void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
//when IBOutlet not be used,use program to makd connection 
EditorViewController* vc = [[EditorViewController alloc]initWithNibName:@"EditorViewController" bundle:nil]; 
self.editorVC = vc; 
vc = nil; 
} 

(void)viewWillAppear:(BOOL)animated{ 
NSLog(@"%@",self.b.name); 
self.labelname.text = self.b.name; 
self.labelnumber.text = self.b.number; 
self.labelsummary.text = self.b.summary; 
} 

(void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

(IBAction)edit:(id)sender{ 
[self presentModalViewController:editorVC animated:YES]; 
} 

@end 

secondeViewController,EditorViewController

#import "EditorViewController.h" 
#import "Example3ViewController.h" 
#import "test.h" 

@interface EditorViewController() 

@end 

@implementation EditorViewController 
@synthesize vtitle; 
@synthesize number; 
@synthesize summary; 

(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
// Custom initialization 
} 
return self; 
} 

(void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 
} 

(void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

(IBAction)done:(id)sender{ 
//[[self parentViewController]dismissModalViewControllerAnimated:YES]; 
//Example3ViewController* e3v = [[Example3ViewController alloc]init];] 

//e3v.name = title.text; 
//e3v.number = number.text; 
//e3v.summary = summary.text; 
//[self dismissViewControllerAnimated:YES completion:^(void){ 

//}]; 
test* t = [[test alloc]init]; 
t.name = self.vtitle.text; 
t.number = self.number.text; 
t.summary = self.summary.text; 
//[t setName:vtitle.text]; 
//[t setNumber:number.text]; 
//[t setSummary:summary.text]; 
Example3ViewController* e3v = [[Example3ViewController alloc] initWithNibName:@"Example3ViewController" bundle:[NSBundle mainBundle]]; 
e3v.b = t; 

[self dismissModalViewControllerAnimated:YES]; 
[t release]; 
[e3v release]; 

} 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
[vtitle resignFirstResponder]; 
[number resignFirstResponder]; 
[summary resignFirstResponder]; 
} 
@end 

臨時變量

#import "test.h" 

@implementation test 
@synthesize name; 
@synthesize number; 
@synthesize summary; 
@end 
+3

你可以請你出示你的代碼嗎? – 2013-05-03 06:04:49

+0

你是否從第二個viewController彈出視圖? – Balu 2013-05-03 06:07:29

+0

http://stackoverflow.com/questions/3545597/passing-variables-from-one-view-to-an-other?rq=1 – 2013-05-03 06:08:27

回答

0

你不能寫

Example3ViewController* e3v = [[Example3ViewController alloc] initWithNibName:@"Example3ViewController" bundle:[NSBundle mainBundle]]; 
e3v.b = t; 

這將創建一個類Example3ViewController的另一個目的和T值分配給該對象不是已在你的棧對象。

您可以編寫類似

Example3ViewController* e3v = [((AppDelegate *)[AppDelegate sharedInstance]).navigationController.viewControllers objectAtIndex:[((AppDelegate *)[AppDelegate sharedInstance]).navigationController.viewControllers count]-1]; 

您可以在SecondViewController分配Example3ViewController變量(比如examplobj)和Example3ViewControllervc.examplobj = selfviewDidLoad