如何从 SecondViewController 修改 FirstViewController 中的 UITextField?
所以我对 Objective C 和 iOS 编程相当陌生。我一边编程一边学习,有一个问题。我试图用我的 Second 修改我的 FirstViewController 中的 UITextField
。我该怎么做?
我在 FirstViewController 中有一个 UITextField
名称,并且希望能够使用按钮在 SecondViewController 内执行类似 firstViewController.name.text = @"new name";
的操作值已更改,以便如果我将选项卡切换回 FirstViewController,我会看到已进行更改。
预先感谢您的任何帮助。
So I am fairly new to objective C and iOS programming. I am learning as I program and have a question. I am trying to modify a UITextField
in my FirstViewController with my Second. How do I do this?
I have a UITextField
name in FirstViewController and would like to be able to do something like firstViewController.name.text = @"new name";
inside of SecondViewController with a button and have the value changed so that if I switch tabs back to the FirstViewController I see the change has been made.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1、将FirstViewController设置为SecondViewController的委托;
2、使用NSNotificationCenter通知变更事件。
1、Set the FirstViewController as the delegate of SecondViewController;
2、Use NSNotificationCenter to notify the change event.
很好调用
您只需要在第二个视图控制器内引用第一个视图控制器。有多种方法可以传递引用。可以通过应用程序委托。
不需要您在第二个视图控制器中引用第一个视图控制器的另一个选项是使用 NSNotificationCenter
然后你可以让你的第二个视图控制器观察一个名为 say 的通知@“namechange”,其中包含新的名称字符串。
当按下该按钮时,您将附加新名称的通知发布到 NSNotificationCenter。所有信息都在上面的链接中,或者只需谷歌 NSNotificationCenter 即可获取更多教程和信息。
Well to call
You just need a reference to your first view controller inside of your second view controller. There are a number of ways to pass a reference around. Could go through the app delegate.
Another option that doesn't require you to have a reference to the first view controller inside the second view controller is to use NSNotificationCenter
Then you can have your second view controller observe a notification named say @"namechange" which contains the new name string.
When the button is pressed, you post a notification to the NSNotificationCenter with the new name attached. All the info is in the link above, or just google NSNotificationCenter for more tutorials and info.