传送数据 Passing Data Between Views (实例)

Passing Data Between Views

In this tutorial i will be showing you how to create multi functioning buttons 

Features:

  • 1 Label
  • 1 UITextField
  • 2 Buttons
  • 2 Views

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

 

The Code

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

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值