I have the delegate method I implement to pass data from FirstViewController to SecondViewController.
First, I created a text Field and Button in FirstViewController. Second, I created a label to display the data in SecondViewController.
How it should work:
The user will press the button in FirstViewController
and it will pass the data to the secondViewController
.In addition,the user will be using a UISwipeGestureRecognizer to navigate to the second view controller, so there's no need to use the button to go to the second view controller.
How I test the application
1- I run the application. --> 2- I type "Hello" in Text field --> 3- I press the button --> 4- I swipe to the second view controller to see the data --> 5- I don't see any data in the label ??
First i created the delegate protocol
FirstViewController.h
@class FirstViewController;
@protocol FirstControllerDelegate
-(void) updateLabel:(NSString*)string
@end
@property (weak, nonatomic) id<FirstViewControllerDelegate>delegate;
@property (weak, nonatomic) IBOutlet UITextField *TextField;
- (IBAction)button:(id)sender;
FirstViewController.m
@interface FirstViewController. ()
@end
@implementation ViewController1
@synthesize delegate;
@synthesize TextField;
-(void)viewDidLoad{
[super viewDidLoad];
}
- (IBAction)Button:(id)sender {
ViewController2 *vc2 = [[ViewController2 alloc] init];
vc2.stringfromTextfield1 = self.TextField.text;
}
SecondViewController.h
#import "SecondViewController.h"
#import "FirstViewController.h"
@interface SecondViewController : UITableViewController<FirstControllerDelegate>
@end
@property (weak, nonatomic) IBOutlet UILabel *Label;
@property (strong, nonatomic) NSString *stringfromTextfield1;
SecondViewController.m
@interface SecondViewController. ()
@end
@implementation SecondViewController
-(void)viewDidLoad{
[super viewDidLoad];
self.label.text = self.stringfromTextfield1;
}
I appreciate your time and effort to help me out
ViewController2
object. – Larme