如何从xcode storyBoard中的不同UIViewController获取值?
答案 0 :(得分: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;
答案 1 :(得分:0)
在你的第二个VIew控制器中
- (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文件中的第三个viewcontroller
@property (nonatomic, retain) NSString* labelString;
<。>文件中的
- (void)viewDidLoad
{
[super viewDidLoad];
yourLabel.text = labelString;
}
答案 2 :(得分: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"];