2017-08-30 94 views
1

我有一个UIViewController几个塞格斯深,当使用完毕后,应unwind并带他们回DashboardViewController。平仓防止委托被称为

我创建了仪表板的unwindToDashboard方法和钩住我的FinishViewController一个按钮到Exit。所以,当它的点击将启动展开动作。

这工作正常。

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

因此,我为FinishViewController创建了一个代理ProcessDataDelegate,并使仪表板符合它。

然而,在仪表板的委托方法是调用。

谁能告诉我,我做了什么错?

DashboardViewController.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 

FinishViewController.h

@class FinishViewController; 
@protocol ProcessDataDelegate <NSObject> 
    @required 
    - (void) didFinishWithResults: (NSDictionary*)dictionary; 
@end 

@interface FinishViewController : UIViewController 
@property (nonatomic, weak) id <ProcessDataDelegate> delegate; 
@end 

FinishViewController.m

@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 
+1

如果您正在使用塞格斯和故事情节,你不能实例化一个的viewController与[页头] INIT]你需要得到您的目的地视图控制器在赛格瑞方法准备并通过委托有 –

+0

如果有什么需要的SEGUE为4个或5塞格斯吗?这就是我使用展开功能的原因。 –

+0

但只有一个去finishViewController不是吗?,并有一个标识符? –

回答

1

你需要通过你的委托在DashboardViewControllerprepareForSegue方法,有获得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 
    } 
}