私は、次のことを実行するViewController
を持ってUIButton
います:
- (IBAction)buttonClicked:(id)sender
{
NSLog(@"Button clicked, lets move to next controller to do stuff");
[self performSegueWithIdentifier:@"toNextController" sender:nil];
}
これは私の次へと移りますが、ViewController
これまでのところ驚くべきことは何もありません。
2番目の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";
}
}
私がこれまでに試みたのは、メインコントローラーにリンクする2番目のセグエを作成し、セグエを実行する前に、そのハンドルをつかんでデータを設定することです。それが戻るのに最適な方法かどうかはわかりません。
質問:
を実行するときにデータを返すことは可能[self dismissModalViewControllerAnimated:YES];
ですか、それとも戻りの旅のためにセグエを実装する必要がありますか?