I have got two ViewController:
1) ViewController
2) TestAppViewController
In ViewController.h
Using delegate:
In TestAppViewController.h:
@protocol messageDelegate <NSObject>
@optional
-(void)test:(NSString*)str;
@end
@interface SecondViewController : NSString
@property (nonatomic, assign) id <messageDelegate> delegate;
@end
In TestAppViewController.m:
-(void)readyToSend
{
[self.delegate test:@"Hello world!"];
}
In ViewController.h:
@interface ViewController : UIViewController<messageDelegate>
@end
In ViewController.m: in
- (void)viewDidLoad {
TestAppViewController * testAppViewController = [[TestAppViewController alloc] init];
testAppViewController.delegate = self;
}
-(void) test:(NSString*)str{
NSLog(@"%@,str");
}
Hope it will help!