2017-08-30 71 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 
    } 
} 
相關問題