2017-08-06 17 views
0

私はタブバーを持っています。最初のタブはHomeViewControllerで、2番目のタブはnavigationControllerに2つのViewController - CheckOutViewControllerPaymentViewControllerを持っています。TabBarのViewControllers間のデリゲートは呼び出されません

HomeViewControllerを更新できるPaymentViewControllerに代理人を追加しようとしています。

ただし、HomeViewControllerのデリゲートメソッドは呼び出されません。私が理解から

PaymentViewController

@protocol PaymentViewControllerDelegate <NSObject> 

@required 
-(void)paymentSuccessfull :(BOOL)isSuccessfull; 
@end 

@interface PaymentViewController 
@property (nonatomic, weak) id <PaymentViewControllerDelegate> paymentDelegate; 

-(void)orderProcessed 
{ 
    [paymentDelegate paymentSuccessfull : YES]; 
    [self.navigationController popToRootViewControllerAnimated :YES]; 
} 

HomeViewController.m

@interface HomeViewController : UIViewController<PaymentViewControllerDelegate> 

// I do not know how to assign delegate here in the tabbar 
-(void)paymentSuccessfull:(BOOL)isSuccessfull 
{ 
    NSLog(@"success"); 
} 
+0

HomeViewControllerでPaymentViewControllerのインスタンスを使用しましたか? –

+0

いいえ、タブバーはコントローラの遷移を表示するために使用されています。 – hotspring

+0

HomeViewController内でPaymentViewControllerのインスタンスを使用していないため、そのデリゲートメソッドを使用できますが、HomeViewController内でそのメソッドを呼び出す場合は、NSNotificationCenterを使用してorderProcessed内に通知をポストし、HomeViewControllerに通知します。 –

答えて

0

は、あなたがこのようないくつかの構造を有することである。

タブバーコントローラ:

  • HomeViewController
  • NavigationController

    • PaymentViewController

    • CheckOutViewController

あなたの構造に応じて、PaymentViewController にプロトコルを追加しましたので、今

デリゲートメソッドは、(私はNavigationController /タブバーであるかもしれないあなたのケースで推測あなたがPaymentViewControllerをインスタンス化しているところからコントローラに呼び出されなければなりませんコントローラ)。 したがって、これらのコントローラの中で、ストーリーボードからPaymentViewControllerをインスタンス化した場合は、そのクラスがデリゲートにも適合するように指定する必要があります()。

それは次のようになります:私は、これはあなたを助けるか、あなたの方向性を与えるべきだと思う

paymentViewControllerObj.delegate = self; 

+0

詳細を確認するにはこちらをご確認ください https://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c –

関連する問題