简体   繁体   English

如何在两个uiview之间传递参数

[英]How to pass parameters between two uiview

I have to send parameters between two UIView. 我必须在两个UIView之间发送参数。 This is how I'm loading the second UIView from the first: 这就是我从第一个加载第二个UIView的方式:

SingleViewController *single = [[SingleViewController alloc] initWithNibName:@"SingleViewController" bundle:nil];
[self.view addSubview:single.view];

How can i send some NSString to the other view? 如何将NSString发送到其他视图?

If I understand you correctly, then I think you would send the NSString to the view controller (single) and not the view (single.view). 如果我对您的理解正确,那么我认为您会将NSString发送到视图控制器(单个),而不是视图(single.view)。 Two common ways to do this come to mind. 我想到了两种常见的方法。 Set up a property for SingleViewController class in it's .h file using @property, and then either: 1. set the property like 使用@property在.h文件中为其设置SingleViewController类的属性,然后执行以下任一操作:1.将属性设置为

single.somestring = @"this is a string";

or 2. Create a new init method for SingleViewController and pass it in that way. 或2.为SingleViewController创建一个新的init方法,并以这种方式传递它。

   SingleViewController *single = [[SingleViewController alloc] initWithMyString:@"this is a string" withNibName:@"SingleViewController" bundle:nil];

where you have declared initWithMyString:withNibName:bundle : in your SingleViewController.h file and in it you call initWithNibName:bundle : for the parent class. 在那里你已宣布initWithMyString:withNibName:bundle :在你的SingleViewController.h文件,并在你调用initWithNibName:bundle :对父类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM