iOS在两个视图之间传递数据

时间:2015-07-22 03:51:53

标签: ios

我正在使用两个视图(视图控制器VC1和VC2)并将数据从VC1传递到VC2 我在VC2中存储了两个变量的值

  //VC1 store obj to VC2
self.VC2.twtid=ide;
self.VC2.urlString=[[NSURL alloc]  initWithString:vurl];

显示VC2后我收到了值。 我的问题是当我第二次点击VC1中的任何单元格时。 当我再次导航回VC1(tableview)并尝试选择单元格时,不会再次存储这些值。

  //VC.h I declare the two var 
@property(strong, nonatomic) NSNumber *twtid;

@property(strong, nonatomic) NSURL *urlString;

注意:我没有使用prepareForSegue.without Segue !!

3 个答案:

答案 0 :(得分:1)

使用全局变量其他使用Segue方法。

答案 1 :(得分:0)

ViewController2 *VC2 = (ViewController2 *)[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
VC2.url = urlString; // use your variable over here, this is just and example
[self presentViewController:VC2 animated:YES completion:^{         }];
[self.navigationController pushViewController:VC2 animated:YES];
根据您的要求

用户presentViewController或pushViewController

答案 2 :(得分:0)

您不需要将VC2存储为VC1的属性,只需每次都启动它。

相关问题