如何在视图之间传递文本
我发表了 2 次观点 我想将主视图上的标签文本发送到子视图 想要将其打印在另一个标签的文本值上...... 如何传递该文本
i made 2 views
and i want to send text of label on main view to sub view to
an want to print it there on another label's text value....
how to pass that text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不会使用单例模式或任何其他“全局变量”。这将使您的视图控制器非常紧密地耦合并限制可重用性。我只需在第二个视图控制器中创建一个实例变量,并在呈现视图之前将其设置在主视图控制器中。
然后,第二个视图控制器将 label.text 设置为(例如)viewDidLoad 中的实例变量。
这样,第二个视图控制器不依赖于任何“全局变量”或包含,并且将更加可重用。
然后在主视图控制器中:
I wouldn't use a singleton pattern or any other 'global variable'. This will make your view controllers very tightly coupled and restricts reusability. I would just create a instance variable in the second view controller and set this in the main one before presenting the view.
The second view controller then sets the label.text to the instance variable in (for example) viewDidLoad.
This way, the second view controller doesn't depend on any 'globals' or includes and will be more reusable.
Then in the main view controller:
如果类 A 处理您的 view1,类 B 处理 view2,则在类 B 中定义一个接口以接受您的其中一个 UI 元素的新标签,然后从类 A 调用该接口。
If class A handle your view1 and Class B handle view2 then define a interfaces in class B to accept new label to your one of the UI element then call that interface from class A.
查看单例模式。
我的 Objective-C 单例应该是什么样子?
然后你可以做类似的事情:
并且
Look into the Singleton pattern.
What should my Objective-C singleton look like?
Then you could do something like:
and