Ios 从情节提要展开可防止调用委托

Ios 从情节提要展开可防止调用委托,ios,objective-c,delegates,segue,Ios,Objective C,Delegates,Segue,我有一个UIViewController,它有几个深度,当使用完成后,应该展开,并将它们带回仪表板ViewController 我在仪表板中创建了unwindtoadshoard方法,并在我的finishview控制器中的Exit上挂了一个按钮。因此,当其被单击时,将触发“展开”操作 那很好 但我需要将数据从FinishViewController传回仪表板 因此,我为FinishViewController创建了一个委托ProcessDataDelegate,并使仪表板与之一致 但是,仪表板中

我有一个UIViewController,它有几个深度,当使用完成后,应该
展开
,并将它们带回仪表板ViewController

我在仪表板中创建了
unwindtoadshoard
方法,并在我的
finishview控制器中的
Exit
上挂了一个按钮。因此,当其被单击时,将触发“展开”操作

那很好

但我需要将数据从FinishViewController传回仪表板

因此,我为
FinishViewController
创建了一个委托
ProcessDataDelegate
,并使仪表板与之一致

但是,仪表板中的委托方法未被调用

谁能告诉我我做错了什么

仪表板视图控制器.m

#import "FinishViewController.h"

@interface DashboardViewController () <ProcessDataDelegate>{
    FinishViewController *fm;
}
@end

@implementation DashboardViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    if(!fm){
        fm = [[FinishViewController alloc] init];

    }

    fm.delegate = self;
}

- (IBAction)unwindToDashboard:(UIStoryboardSegue *)unwindSegue {
//empty
}

#pragma mark PROTOCOL METHODS

-(void) didFinishWithResults:(NSDictionary*) dictionary{
    NSLog(@"Dashboard method called didFinishWithResults");
}

@end
@interface FinishViewController () 
@end

@implementation FinishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"fired via the button to the exit--- Segue: %@", [segue identifier]);
    [delegate didFinishWithResults:nil ];
}

@end

您需要在
仪表板视图控制器
prepareForSegue
方法中传递您的代表,如果标识符等于预期的序列标识符,则获取
destinationViewController
并转换为
FinishViewController

类似这样的东西

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"fired via the button to the exit--- Segue: %@", [segue identifier]);
    if([[segue identifier] isEqualToString:@"YourSegueIdentifier"])
    {
         ((FinishViewController*)[segue destinationViewController]).delegate = self
    }
}

如果您使用segues和storyboard,则无法将viewController与[[alloc]init]实例化。您需要在prepare for segue方法中获取目标视图控制器,并将代理传递给代理。如果所需segue为4或5 segues,该怎么办?这就是我为什么要使用“展开”功能的原因。但是只有一个可以转到finishViewController?并具有标识符吗?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"fired via the button to the exit--- Segue: %@", [segue identifier]);
    if([[segue identifier] isEqualToString:@"YourSegueIdentifier"])
    {
         ((FinishViewController*)[segue destinationViewController]).delegate = self
    }
}