如何在 UILabel 中显示 UITextField 的文本?
我正在构建一个界面,我可以在其中添加事件,就像在日历中一样。 在 AddAEventViewController 中,我有按钮来设置开始时间、持续时间和重复次数。 每次按下按钮时,视图控制器都会出现一个 UIDatePicker,您可以在其中设置时间。选取的组件将显示在 UITextField 中。现在,当我按下“完成”按钮时,它会关闭 ModalViewController,然后我回到 AddAEventViewController。例如,“持续时间”按钮旁边是一个 UILabel,我想在其中显示刚刚选择的内容并在文本字段中显示持续时间。 如何从其他 ViewController 访问 AddEventViewController?我尝试在那里分配并初始化一个新的,但它不起作用!
- (IBAction)pressedDoneButton:(id)sender {
_mainAddWishViewController.labelDuration.text=textFieldDuration.text;
[self dismissModalViewControllerAnimated:YES];
!
有人可以帮我吗 谢谢朱尔斯
I am building an interface, where I can add events like in a calendar.
In the AddAEventViewController I have Buttons to set the starttime, duration and recurrence.
Every time you press a button a viewcontroller comes up with a UIDatePicker, where you can set your time. The picked component is than displayed in a UITextField. Now when I press the Done-Button, it dismisses the ModalViewController and I am back to my AddAEventViewController. Next to the Durationbutton e.g. is a UILabel, where I want to show now the just picked and in the textfield shown duration.
How do I get access to the AddEventViewController out of an other ViewController? I tried to alloc and init a new one there, but it didnt work!
- (IBAction)pressedDoneButton:(id)sender {
_mainAddWishViewController.labelDuration.text=textFieldDuration.text;
[self dismissModalViewControllerAnimated:YES];
}
Can someone help me please!
Thank you Jules
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以做到这一点,所有这些方法都有记录 这里。阅读和理解它们将对你的iOS软件开发有很大帮助。
There are several ways you can do this, all of them documented here. Reading and understanding them will help you a lot in iOS software development.
有很多方法可以实现这一目标。这是一个相当简单的方法。
在“子”视图控制器中,添加委托属性并将其设置为父视图控制器。
然后在“完成”按钮处理程序中,执行如下操作:
在父视图控制器中,定义如下方法:
基本上,这实现了一个非正式协议,其中 subViewController 通知主视图控制器它已完成并且输入值可用。
请注意,如果您取消 subViewController,请不要发送 didComplete 消息。
There are many ways to achieve this. Here is one that is fairly straightforward.
In the "child" viewController, add a delegate property and set it to the parent view controller.
Then in your Done button handler, do something like:
In the parent view controller, define a method as follows:
Basically, this implements an informal protocol whereby the subViewController informs the main view controller that it is finished and input values are available.
Note that if you cancel out of the subViewController, don't send the didComplete message.