0

I have a tabbar, the first tab has HomeViewController and the second tab has navigationcontroller has two ViewControllers - CheckOutViewController and PaymentViewController.

I am trying to add a delegate on PaymentViewController which allows me to update HomeViewController.

However, the delegate method on the HomeViewController is not getting called.

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");
}
Umar Farooque
  • 2,049
  • 21
  • 32
casillas
  • 16,351
  • 19
  • 115
  • 215
  • Have you used an instance of PaymentViewController in HomeViewController ? – Umar Farooque Aug 06 '17 at 20:23
  • No I did not use, since tab bar is used to viewcontrollers transition. – casillas Aug 06 '17 at 20:24
  • You can use that delegate methods because you are not using an instance of PaymentViewController inside HomeViewController, but if you want to call that method inside HomeViewController you can use NSNotificationCenter and post a notification inside orderProcessed and catch that into HomeViewController. – Paras Gorasiya Aug 07 '17 at 03:13
  • @hotspring did it help ? – Umar Farooque Aug 07 '17 at 05:55

1 Answers1

0

From what I understand is that you have some structure like this:

Tabbar Controller:

  • HomeViewController
  • NavigationController

    • PaymentViewController

    • CheckOutViewController

Now since you've added protocol to PaymentViewController, according to your structure, the delegate method should be called on the Controller from where you are instantiating the PaymentViewController(I guess in your case that might be NavigationController/Tabbar Controller). So,in one of these controller where you would have instantiated PaymentViewController from Storyboard, you would also have to specify that the class conforms to the delegate as well.

It will be something like:

paymentViewControllerObj.delegate = self;

I think this should help you out or give you the direction.

Umar Farooque
  • 2,049
  • 21
  • 32