0

I have a superViewcontroller named CenterViewController in which i have implemented UITabBarController *tabVC and the viewcontroller of tabVC are featureViewController, scheduleViewController, feedbackViewController, contactUsViewController.

they are added as :

tabVC.viewControllers = [NSArray arrayWithObjects:featureViewController,scheduleViewController,feedbackViewController,contactUsViewController, nil];
self addChildViewController:tabVC];
[self.view addSubview:tabVC.view];

I have to access a function named loadHome which is in CenterViewcontroller from feedbackviewcontroller when the feedback is submitted successfully:

-(void) loadHome
{
  [tabVC setSelectedIndex:0];
}

Searched a lot got one solution to implement protocol delegate the code of which is as follows:

centerviewcontroller.h

@protocol CenterViewControllerDelegate <NSObject>
@required
 - (void)loadHome;
@end
@interface CenterViewController : UIViewController <LeftPanelViewControllerDelegate, UITabBarControllerDelegate>
@property (nonatomic, assign) id<CenterViewControllerDelegate> delegate;
@end

feedbackviewcontroller.h

#import "CenterViewController.h"

@interface FeedbackViewController : UIViewController<UIAlertViewDelegate>
{   
  id<CenterViewControllerDelegate> centerdelegate;
}

@property (nonatomic,assign) id<CenterViewControllerDelegate> centerdelegate;

when the button on alertview when feedback is successfully submitted is clicked I am able to call the loadHome function of centerviewcontroller:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  NSLog(@"alert view button index %d", buttonIndex);


  switch(buttonIndex)
  {
    case 0:
        NSLog(@"alert view button index inside switch %d", buttonIndex);
        [self.centerdelegate loadHome];
        break;
    case 1:
        break;
    default:
        break;
  }    
}

The [self.centerdelegate loadHome]; is getting executed but it doesn't take me to the function in centerviewcontroller.

No error nothing happens.

Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76

1 Answers1

0

The reason your delegate method isn't executed is because you didn't set a delegate (aka self.delegate is nil).

Here's a full explanation on how to use delegates including certain protocols and optimizations.

Community
  • 1
  • 1
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76