这是我的应用程序的参数:我有3个viewcontrollers,viewcontroller1
,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;
}
}
viewcontroller3:
-(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];
}
答案 0 :(得分:0)
不要这样做:Viewcontroller2 *popup = [[Viewcontroller2 alloc]init];
相反,请使用ViewController3
的{{1}},它应该是delegate
的现有实例,而不是您即时发明的新实例。