我有臨時變量eneity
和兩個視圖控制器:OneViewController和SecondViewController。他們跳到對方fine.now使用eneity
從OneViewController值發送到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
你可以請你出示你的代碼嗎? – 2013-05-03 06:04:49
你是否從第二個viewController彈出視圖? – Balu 2013-05-03 06:07:29
http://stackoverflow.com/questions/3545597/passing-variables-from-one-view-to-an-other?rq=1 – 2013-05-03 06:08:27