将 NSString 插入 NSString
我是 Objective C 的新手,有一个非常基本的问题。所以我在一个 UIViewController 中有 2 个变量(IBOutlets 是 UITextFields)。用户在这些 UITextFields 中输入文本后,他/她将进入新的视图控制器。当用户输入视图控制器 #2 时,我想将视图控制器 #1 中的 IBOutlet 值插入到 NSString I 预设中。例如,1 个变量是姓名,1 个变量是兴趣。 NSString 应该显示为“Hello [name],感谢您对 [interest] 的兴趣。我们很感激。”那么我如何将 IBOutlet 从 viewcontroller 1 传递到 viewcontroller 2,并将它们作为 NSString 插入到不可变的 NSString 中(感谢您的兴趣等部分)。我很感谢你能提供的任何帮助,因为我是一个完全 Objective C 的新手。感谢您花时间阅读本文。
——雷诺
I'm new to Objective C and have a pretty basic question. So I have 2 variables (IBOutlets that are UITextFields) in one UIViewController. After the user enters text into those UITextFields, s/he proceeds to a new viewcontroller. When the user enters viewcontroller #2, I want to insert the values of the IBOutlets from viewcontroller #1 into an NSString I preset. For example, 1 variable is a name and one is an interest. The NSString should read "Hello [name], thanks for your interest in [interest]. We appreciate it." So how do I pass the IBOutlets from viewcontroller 1 to viewcontroller 2, and insert them as NSStrings into the NSString that isn't variable (the thanks for your interest, etc. etc. part). I appreciate any help you can provide because I'm a total Objective C newbie. Thanks for taking the time to read this.
-Reynold
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个由两部分组成的问题。要按照您想要的方式将这些字符串组合在一起,我建议:
在您的情况下,实现可能有点像这样:
将此值传递给另一个视图控制器有点复杂。我建议在第二个视图控制器中创建一个属性,如下所示:
然后,当您设置新的视图控制器时,您可以像这样配置它:
祝你好运。
This is really a two part question. To put those strings together the way you want to, I'd recommend:
In your case, the implementation would probably be a little like this:
Passing this value to another view controller is a little bit more complicated. I recommend creating a property in the second view controller like so:
Then, when you set up the new view controller you can configure it like this:
Good luck.