2017-08-30 1 views
1

私はUIViewControllerをいくつか持っています。使用が終了したらunwindをDashboardViewControllerに戻す必要があります。ストーリーボードから巻き戻すと、代理人が呼び出されないようにします

ダッシュボードにunwindToDashboardメソッドを作成し、までのボタンをフックしてFinishViewControllerにしました。それがクリックされたときに巻き戻しアクションが発生するようにします。

これは問題なく動作します。

しかし、データを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

ような何かがFinishViewControllerdestinationViewControllerとキャストをそこに着く、あなたのDashboardViewControllerprepareForSegue方法であなたのデリゲートを渡す必要がありますseguesとstoryboardあなたは[[alloc] initでviewControllerをインスタンス化できません。segueメソッドの準備で目的のビューコントローラを取得し、デリゲートをそこに渡す必要があります –

+0

必要なsegueが4または5のセグの場合はどうなりますか?そのため、私は巻き戻し機能を使用しています。 –

+0

しかし、ただ1つはfinishViewControllerに行きますか?あなたは識別子を持っていますか? –

答えて

1

あなたは、識別子は、あなたの期待セグエ識別子

に等しい場合は、使用している場合は、この

- (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 
    } 
} 
関連する問題