objective-c - 你能通过 dismissModalViewControllerAnimated : or do you need a segue for the return journey? 返回数据吗

标签 objective-c ios ios5 storyboard segue

我有一个 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";
    }
}

到目前为止,我尝试做的是创建第二个连接回主 Controller 的转场,在执行转场之前,捕获它的句柄并设置数据。我不确定这是否是返回的最佳方式。

问题:

是否有可能在执行 [self dismissModalViewControllerAnimated:YES]; 时返回数据,或者您是否需要为回程实现 segue?

最佳答案

检查一下:10841897

它描述了使用委托(delegate)和协议(protocol)来回发送信息。它可以根据您的需要稍作更改,只需创建一个 savedWithData: 方法,将字典或您想要的任何数据发送回第一个 View Controller ,而不仅仅是通用的 done 链接中对此进行了描述。

关于objective-c - 你能通过 dismissModalViewControllerAnimated : or do you need a segue for the return journey? 返回数据吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10853868/

相关文章:

ios - 如何检测 AVAudioRecorder 是否暂停?

ios - 如何获取ios 9中的数据模型?

ios - 为什么我的 UITableView 没有填充评论

iphone - 如何延迟执行 Segue

image-processing - 二进制图像上的快速像素计数 - ARM neon 内在函数 - iOS Dev

iphone - 电话号码的 NSTextCheckingResult

ios - 表格 View 不会推送到下一个 View

objective-c - CS193p-向计算器添加退格键

objective-c - Objective C 在两个字符串连接之间插入变量

ios - NSNumber 在 Objective-C 中存储 NSDictionary 的对象