私はタブバーを持っています。最初のタブはHomeViewController
で、2番目のタブはnavigationControllerに2つのViewController - CheckOutViewController
とPaymentViewController
を持っています。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");
}
HomeViewControllerでPaymentViewControllerのインスタンスを使用しましたか? –
いいえ、タブバーはコントローラの遷移を表示するために使用されています。 – hotspring
HomeViewController内でPaymentViewControllerのインスタンスを使用していないため、そのデリゲートメソッドを使用できますが、HomeViewController内でそのメソッドを呼び出す場合は、NSNotificationCenterを使用してorderProcessed内に通知をポストし、HomeViewControllerに通知します。 –