这是我的应用程序的情景:我有 3个视图控制器、、、、viewcontroller1
。在中,我只有一个按钮,单击此按钮时,我添加了一个弹出窗口,其中包含一个文本字段。当我再次编辑我的文本字段时,我添加了只包含一个pickerview 的内容。我要做的是从pickerview 中传递选定的对象,并将其传递到我单击完成按钮时的文本字段。viewcontroller2
viewcontroller3
viewcontroller1
viewcontroller2
viewcontroller3
viewcontroller2
这是我的代码:
//Viewcontroller1 : add the Viewcontroller2
- (void)withContractAction:(id)sender
{
Viewcontroller2 *addViewController = [[Viewcontroller2 alloc] initWithNibName:@" Viewcontroller2 " bundle:nil];
addViewController.delegate = self;
addViewController.modalPresentationStyle = UIModalPresentationFormSheet;
addViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addViewController animated:YES];
addViewController.view.superview.frame = CGRectMake(150, 300, 460, 300);
[addViewController release];
}
在viewcontroller2
我添加viewcontroller3
:
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
Viewcontroller3 *addViewController = [[Viewcontroller3 alloc] initWithNibName:@" Viewcontroller1" bundle:nil];
addViewController.delegate = self;
addViewController.modalPresentationStyle = UIModalPresentationFormSheet;
addViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:addViewController animated:YES];
addViewController.view.superview.frame = CGRectMake(50, 740, 695, 245);
self.textfield.text = contrat.NUM_CONTRACT;
}
}
视图控制器3:
-(IBAction)done:(id)sender{
Viewcontroller2 *popup = [[Viewcontroller2 alloc]init];
//contrat is my object that I need to pass , from Viewcontroller3 to Viewcontroller2 ,so I included it into my interface in Viewcontroller2 ,
popup.contrat = sometxt;
[self.navigationController pushViewController:popup animated:YES];
[self dismissModalViewControllerAnimated:YES];
[orderForm dismissModalViewControllerAnimated:YES];
[popup release];
}