【发布时间】:2012-06-06 21:45:35
【问题描述】:
我有一个ViewController,它有一个UIButton,它执行以下操作:
- (IBAction)buttonClicked:(id)sender
{
NSLog(@"Button clicked, lets move to next controller to do stuff");
[self performSegueWithIdentifier:@"toNextController" sender:nil];
}
这只是转移到我的下一个ViewController,到目前为止没有什么了不起的。
在第二个ViewController中,我会做一些我的应用逻辑,然后返回。
- (IBAction)backButtonPressed:(id)sender
{
NSLog(@"Back button clicked, lets just drop out of here...");
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)saveButtonPressed:(id)sender
{
NSLog(@"save button clicked, lets send some data back");
[self performSegueWithIdentifier:@"backToMain" sender:nil];
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"backToMain"])
{
NSLog(@"Preparing segue for backToMain");
// Obtain handles on the current and destination controllers
MainController * startingViewController;
SecondController * destinationController;
startingViewController = (MainController * ) segue.sourceViewController;
destinationController = (SecondController * ) segue.destinationViewController;
// set data on the main controller
startingViewController.myString = @"SomeDummyString";
}
}
到目前为止,我尝试做的是创建第二个链接回主控制器的转场,在执行转场之前,抓住它的句柄并设置数据。我不确定这是否是返回的最佳方式。
问题:
是否有可能,在执行[self dismissModalViewControllerAnimated:YES]; 时返回数据,或者您是否需要为回程实现一个segue?
【问题讨论】:
-
我不会对第一个控制器执行另一个 segue。据我了解,这会创建一个全新的 Controller 类实例,实际上,您只是在添加越来越多的控制器,因为它们彼此来回切换。我会使用委托/协议方法。看到这个:stackoverflow.com/questions/10841653/…
标签: objective-c ios ios5 storyboard segue