我有临时变量eneity
和两个 ViewController:OneViewController和SecondViewController。它们相互跳转很好。现在用于eneity
将值从OneViewController发送到SecondViewController。但是当 SecondViewController 返回值时eneity
,OneViewController 无法再获得返回值。
我想知道我是否可以使用变量来获取返回值,而不是委托?
感谢您的帮助;
添加:
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