我对编程一般都很陌生。我正在尝试制作一个非常简单的应用程序。使用故事板在xcode中的两个视图控制器之间传递数据
我想将数据从一个viewcontroller传递到另一个使用故事板。在我的第一个屏幕上,我有一个文本框和一个按钮,然后按下按钮后,我希望第二个屏幕的标签可以随文本字段中的任何文本更新。
下面是我的一些代码:
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface FirstViewController()
@end
@implementation FirstViewController
@synthesize secondviewData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)passData:(UIButton *)sender {
// SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
self.secondviewData = secondviewData;
secondviewData.passedValue = input.text;
// [self presentViewController:second animated:YES completion:nil];
homeLabel.text = input.text;
}
@end
#import "SecondViewController.h"
#import "FirstViewController.h"
@interface SecondViewController()
@end
@implementation SecondViewController
@synthesize passedValue;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
label.text = passedValue;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这里是我的代码的链接:http://oberober.com/passingData/
到目前为止第二个屏幕上的标签一直一片空白不管我在第一屏的输入文本域。
我觉得我错过了一个重要的概念?任何提示或教程,我可以看看?
由于时间提前, 卡斯帕
搜索是你的朋友:http://stackoverflow.com/search?q=ios+pass+data+between+storyboard – rmaddy 2013-03-09 06:45:31