我有一个标签栏,第一个标签有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中。 –