我有一个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";
}
}
到目前为止,我尝试做的是创建第二个链接回主控制器的转场,在执行转场之前,抓住它的句柄并设置数据。我不确定这是否是返回的最佳方式。
问题:
是否有可能在执行 a 时返回数据[self dismissModalViewControllerAnimated:YES];
,或者您是否需要为回程实施 segue?