您的位置:首页 > 移动开发 > IOS开发

iOS storyboard 界面间传值

2015-06-24 10:08 591 查看
比如要从viewcontroller1向viewcontroller2传递参数

需要首先有两个界面 设置storyboard segue中的identifier 1界面中有一个按钮 用于控制信息传递

1.对ViewController.m的操作:

添加头文件

#import "ViewController2.h"

@interface ViewController ()

@end

- (IBAction)buttonname:(id)sender {

[self performSegueWithIdentifier:@"跳转界面的名称" sender:sender]; //在storyboard segue中的identifier中查看
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"跳转的界面名称"]) {

ViewController2 *viewcontroller2= (ViewController2 *)segue.
destinationViewController;

ViewController2.info = @"传递的参数";
}

}

2.在ViewController2.h中添加

@property (strong,nonatomic)NSString *info; //传递的参数

3.在ViewController2.m中添加

- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.

NSString *str = self.info;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: