当我转到ViewController2时,我想传递值并从ViewController1显示到ViewController2。数据未显示在视图上。但我检查po data.odrNum它有值。
ViewController1
ViewController2 *data = [[ViewController2 alloc] init];
data.odrNum = [respondData valueForKey:@"orderCode"];
ViewController2.h
@property (strong, nonatomic) NSString *odrNum
;
ViewController2.m
self.orderConNum.text = self.odrNum;
这就是我呈现ViewController2的方式
UIStoryboard * storyboard = self.storyboard;
OrderDetailsViewController *detail = [storyboard instantiateViewControllerWithIdentifier: @ "OrderDetailsViewController"];
[self.navigationController pushViewController:detail animated:YES];
答案 0 :(得分:-1)
按下viewcontroller时传递数据。
UIStoryboard * storyboard = self.storyboard;
OrderDetailsViewController *detail = [storyboard instantiateViewControllerWithIdentifier: @ "OrderDetailsViewController"];
detail.odrNum = [respondData valueForKey:@"orderCode"]; // this line you must put when you want to pass data.
[self.navigationController pushViewController:detail animated:YES];
答案 1 :(得分:-1)
您是否考虑过使用sharedSingleton:
在Dropbox文件中是我使用的sharedSingleton
个文件。
在Changables.h
文件中,您可以添加要使用的变量,并且可以导入在您要使用的UIViewControllers
上
要设置此项,您只需使用:
[Changables sharedSingleton].yourVariable = @"my variable data"
要获取数据,您可以使用
[Changables sharedSingleton].yourVariable.
我也使用它来使用自定义对象。