我有一個標籤欄,第一個標籤有HomeViewController
和第二個標籤有導航控制器有兩個ViewControllers - CheckOutViewController
和PaymentViewController
。TabBar之間的ViewControllers之間的委託沒有被調用
我想在PaymentViewController
上添加一個代理,它允許我更新HomeViewController
。
但是,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中。 –