Search code examples
iphoneiosobjective-cecslidingviewcontroller

Objective-c multiple delegates in the same view - ECSlidingViewController


I started testing ECSlidingViewController and after I tried to access FirstTopViewController I have a big trouble - because in FirstToViewController I already have ZBarReaderDelegate implemented and all examples of delegate are not triggering any method from my delegate.

Basically I have this stuff:

FirstTopViewController.h

#import ...MyStuff...
#import "UnderRightViewController.h"

@interface FirstTopViewController : UIViewController <RightViewDelegate, ZBarReaderDelegate>

@property (weak, nonatomic) IBOutlet UITextView *labelTotal; 

@end

FirstTopViewController.m

#import "FirstTopViewController.h"

@implementation FirstTopViewController
- (void)setTotalViewController:(UnderRightViewController*)controller didTotalChange:(NSString*)total
{
    //labelTotal.text = total;
    NSLog(@"I'm here!!! and received %@", total);
}

From other side I have

UnderRightViewController.h

#import <UIKit/UIKit.h>
#import "ECSlidingViewController.h"

@class UnderRightViewController;

@protocol RightViewDelegate <NSObject>

- (void)setTotalViewController:(UnderRightViewController*)controller didTotalChange:(NSString*)total;

@end

@interface UnderRightViewController : UITableViewController

@property (nonatomic, weak) id <RightViewDelegate> delegate;

@end

UnderRightViewController.m

#import "UnderRightViewController.h"

@interface UnderRightViewController ()

@end

@implementation UnderRightViewController

@synthesize delegate;

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [delegate setTotalViewController:self didTotalChange:@"foo"];
}
@end

I'm trying this entire day solve this puzzle but I never get setTotalViewController fired.

Thanks in advance.


Solution

  • Friend you did a small mistake, when you navigate from FirstTopViewController to UnderRightViewController at that time you need to do this in FirstTopViewController.m:-

     UnderRightViewController *obj = [[UnderRightViewController
                                                                      alloc] initWithNibName:@"UnderRightViewController" bundle:nil];
    
    obj.delegate  = self; // u forget to assign protocol handler
    
    
    [self.navigationController pushViewController:obj animated:YES];
    
    
    [obj release];