Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- iOS - Passing variable to view controller
- SetTeamsViewController *vc = [[SetTeamsViewController alloc] init];
- vc.myLabel.text = self.teamCount;
- [self presentModalViewController:vc animated:YES];
- [vc release];
- SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:self.teamCount];
- - (id)initWithTeamCount:(int)teamCount {
- self = [super initWithNibName:nil bundle:nil];
- if (self) {
- // Custom initialization
- self.teamCountLabel.text = [NSString stringWithFormat:@"%d",teamCount];
- }
- return self;
- }
- SetTeamsViewController *vc = [[SetTeamsViewController alloc] initWithTeamCount:teamCount];
- - (id)initWithTeamCount:(int)teamCount {
- self = [super init];
- if (self) {
- // Custom initialization
- str = [NSString stringWithFormat:@"%d",teamCount];
- }
- return self;
- }
- self.teamCountLabel.text = str;
- [super viewDidLoad];
- SetTeamsViewController *vc = [[SetTeamsViewController alloc] init];
- [self presentModalViewController:vc animated:YES];
- vc.myLabel.text = self.teamCount;
- [vc release];
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController
- {
- // please make your control on XIB set these IBOutlet's
- //I'm not showing how to connect these with XIB
- IBOutlet UILabel *lblView;
- IBOutlet UIButton *buttonGo;
- }
- //this is method which will push the view
- -(IBAction)buttonGoClickAction:(id)sender;
- -(IBAction)buttonGoClickAction:(id)sender
- {
- SecondViewController *secondViewObject = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
- //before pushing give the text
- secondViewObject.string = lblView.text;
- [self.navigationController pushViewController:secondViewObject animated:YES];
- }
- #import <UIKit/UIKit.h>
- @interface SecondViewController : UIViewController
- {
- IBOutlet UILabel *labelView;
- NSString *string;
- }
- //set the string property
- @property(nonatomic, retain) NSString *string;
- @end
- #import "SecondViewController.h"
- @implementation SecondViewController
- //synthesize string here
- @synthesize string;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- //Here you will get the string
- labelView.text = string;
- }
- // view1.h
- @interface view1 : UIViewController {
- NSString *passingVariable;
- }
- @property (nonatomic, strong) NSString *passingVariable;
- @end
- // view1.m
- @implementation view1
- @synthesize passingVariable;
- // the rest of the implementation
- @end
- // view2.m
- #import "view1.h"
- @implementation view2
- -(IBAction)changeview
- {
- view1 *myview = [[view1 alloc] init];
- myview.passingVariable = [NSString stringWithString:@"Hello Variable"];
- [self.navigationController pushViewController:myview animated:YES];
- }
- @end
Add Comment
Please, Sign In to add comment