-5

//viewcontrollerA.h

@class viewA;
@protocol viewADelegate<NSObject>
- (void)emailidgetmethod:(NSString *)string;

@end

@interface Login : UIViewController
{

}
@property (nonatomic,assign) id <viewADelegate> delegate;
@end

//viewcontrollerA.m

#import "viewcontrollerA.h"
 @synthesize delegate;

 - (void)viewDidLoad 
  {
   [self.delegate emailidgetmethod:@"myString"];
  }

//viewcontrollerB.h

  #import "viewcontrollerA.h"
  @interface viewcontrollerB : UIViewController<viewADelegate>
  @end

//viewcontrollerB.m #import "viewcontrollerB.h"

   - (void)viewDidLoad 
   {
       viewcontrollerA *viewA= [[viewcontrollerA alloc]init];
       [viewA setDelegate:self];
   }

 - (void)emailidgetmethod:(NSString *)string
   {
       NSLog(@"Delegatehomemethod %@",string); // This is not calling.
   }
soumya
  • 3,801
  • 9
  • 35
  • 69
Deepak ravi
  • 43
  • 10

3 Answers3

-1

Method doesn't calling because viewDidLoad method of viewControllerA doesn't calling. You should add viewControllerA as child to viewControllerB and add view of viewContollerA as subview of viewControllerB's view

Sergei Stralenia
  • 855
  • 7
  • 16
-1

I think, your ViewControllerA is loading first and then you navigate to ViewControllerB Controllers. If that is your case, your delegate function will not call because as you can see, when your ViewControllerA is loaded and viewDidLoad is called, your delegate is nil so it will not able to call function.

So you need to load ViewControllerB first and navigate to ViewControllerA

Thanks

Hindu
  • 2,894
  • 23
  • 41
-1

You are calling an instance method which is declared in ViewControllerA in another ViewController. This won't be called because you can only access that method within ViewControllerA. You can change the -(void) to +(void), to make it a class method. Then in your ViewControllerB, create an instance of ViewControllerAViewControllerA *VCA = [[ViewControllerA alloc] init]; Then you can access this method within ViewControllerA.[VCA methodName];

Dovahkiin
  • 1,239
  • 11
  • 23