Passing Data Between Views
In this tutorial i will be showing you how to create multi functioning buttons
Features:
Passing dada between views is very handy if you require content to move throughout you application its also very helpful for games where your score or info can be passed to the next view where theres leader boards or extra content
Play the video to get a step by step walkthrough and all code can be copy and pasted |
ViewController.h
#import <UIKit/UIKit.h> #import "secondview.h" @interface ViewController : UIViewController { secondview *secondviewData; __weak IBOutlet UITextField *textfield; } @property (nonatomic,retain)secondview *secondviewData; - (IBAction)passdata:(id)sender; @end
ViewController.m
#import "ViewController.h" #import "secondview.h" @implementation ViewController @synthesize secondviewData; -(IBAction)passdata:(id)sender { secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil]; self.secondviewData = second; secondviewData.passedValue = textfield.text; [self presentModalViewController:second animated:YES]; }
Secondview.h
#import <UIKit/UIKit.h> @interface secondview : UIViewController { __weak IBOutlet UILabel *label; NSString *passedValue; } @property (nonatomic,retain)NSString *passedValue; - (IBAction)back:(id)sender; @end
Secondview.m
#import "ViewController.h" @implementation secondview @synthesize passedValue; -(IBAction)back:(id)sender { ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil]; [self presentModalViewController:second animated:YES]; } - (void)viewDidLoad { label.text = passedValue; [super viewDidLoad]; // Do any additional setup after loading the view from its nib. }
视频:http://www.youtube.com/watch?v=Y4zmM_Rqv6Y&feature=player_embedded