In this same we have 2 ViewControllers, a textbox and a button on the first and a label on the second. The idea is that the textbox from the first view sets the label in the second view, via a button.
FirstViewController.h:
FirstViewController.m:
SecondViewController.h:
The important part of the code is here
Replacing SecondViewSegue with the name of your segue.
~Youmu
FirstViewController.h:
Code:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController{
IBOutlet UIButton *button;
IBOutlet UITextField *textbox;
}
@end
FirstViewController.m:
Code:
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation FirstViewController
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
textbox.text = @"Test";
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
}
-(void) buttonPressed
{
[self performSegueWithIdentifier:@"SecondViewSegue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"SecondViewSegue"]) {
SecondViewController *secondview = [segue destinationViewController];
secondview.PushedData = textbox.text;
}
}
@end
SecondViewController.h:
Code:
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
{
NSString *PushedData;
IBOutlet UILabel *lable;
}
@property (nonatomic,strong) NSString *PushedData;
@end
Code:
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize PushedData;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
lable.text = PushedData;
}
@end
The important part of the code is here
Code:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"SecondViewSegue"]) {
SecondViewController *secondview = [segue destinationViewController];
secondview.PushedData = textbox.text;
}
Replacing SecondViewSegue with the name of your segue.
~Youmu