-3

如何从 xcode storyBoard 中的不同 UIViewController 获取值?

4

3 回答 3

1

我最终使用了 prepareForSegue 方法。首先我在我的第三个视图控制器中创建一个字符串。

@property (strong,nonatomic) NSString* stringFromSecondView;

然后我给了push segue一个名为“getDate”的ID,在我的第二个视图类中使用下面的代码并记住导入thirdviewcontroller.h

#import "thirdViewController.h"

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"getDate"]){
        NSString *intro = _myDate.text;
        thirdViewController *vc = [segue destinationViewController];
        vc.stringFromSecondView = intro;
    }
}

现在回到我的thirdViewController.m

_myLabel.text = stringFromSecondView;
于 2013-01-12T16:17:53.697 回答
0

在您的第二个视图控制器中

- (IBAction) btnPressToBringThirdView : (id) sender
{
      ThirdViewController* newObject = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
      newObject.labelString = @"whatever text you want";
      [self.navigationController pushViewController:newObject];
      [newObject release];
} 

在 .h 文件中的第三个视图控制器中

@property (nonatomic, retain) NSString* labelString;

在 .m 文件中

- (void)viewDidLoad
{
     [super viewDidLoad];
     yourLabel.text = labelString;
}
于 2013-01-12T07:11:33.113 回答
0
ViewController *secondview=[[ViewController alloc]init];

secondview.your var here= secondview.your var here+100;//whate you var to change if NSintager

///保存你的var

[[NSUserDefaults standardUserDefaults]setInteger:secondview.your var here forKey:@"your key to save"];
于 2013-12-26T07:45:13.500 回答