如何在子视图中创建按钮以更新其父视图中的信息? [英] How to make button in child view to update information in its parent view?
问题描述
所以我想创建一个iPhone应用程序,其中有两个视图通过 UINavigationController
连接。假设第一个视图是ViewA,它是应用程序启动时的初始视图。然后ViewA转到ViewB,这是另一个视图。 ViewA上有一个 UIButton
A和一个 UILabel
A和 UIButton
一个segll到ViewB(即按下按钮时,用户显示ViewB。在ViewB中,还有一个 UIButton
B,按下时,可以更新ViewA中的 UILabel
A。(事实上,ViewB中应该有很多 UIButton
Bs但是为了简单起见我们只说一个这就是我想要实现的目标,这就是我所做的。
So I want to make an iPhone app in which there are two views connected by UINavigationController
. Let's say that the first view is ViewA and it's the initial view when the app is launched. Then ViewA segues to ViewB which is the other view. There is a UIButton
A and a UILabel
A on ViewA and the UIButton
A segues to ViewB (i.e. when pressing the button, the user is shown ViewB. In ViewB, there is also a UIButton
B that, when pressed, can update the UILabel
A in ViewA. (In fact, there should be many UIButton
Bs in ViewB but let's just say one for simplicity. That's what I want to achieve and here are what I've done.
我创建了两个视图和一个通用的 UINavigationController
并将ViewA生成根,以便在启动应用程序时正确显示初始视图。
I've created the two views and a generic UINavigationController
and rooted ViewA to it so the initial view is correctly shown when the app is launched.
我已设置 UILabel
A和 UIButton
A在ViewA中并将 UILabel
A作为出口属性连接到ViewAViewController。
I've set up the UILabel
A and UIButton
A in ViewA and connect the UILabel
A as an outlet property to ViewAViewController.
我在 ViewAViewControllerB
中导入 ViewAViewControllerA
。
我一直在猜(推模式) UILabel
A A
A到查看
B,它按预期工作。
I've segued (push mode) UILabel
A on View
A to View
B and it works as intended.
我也知道如何在 ViewAViewController
中更新 UILabelA
使用 self.UILabelA.text
但是我无法在 ViewBViewController
上执行此操作,因为我无法调用 self
我不知道 ViewAViewController
的对象名称。那是:我想我应该使用?。UILabelA.text
但我不知道应该用什么来替换?
。
I also know how to update UILabelA
in ViewAViewController
by using self.UILabelA.text
but I can't do it on ViewBViewController
because I can't call self
and I don't know the name of the object of ViewAViewController
. That is: I think I should use ?.UILabelA.text
but I don't know what should be put to replace ?
.
顺便说一下,我正在使用XCode 4.6和iOS 6的开发以及故事板模式。
By the way, I'm using XCode 4.6 and development for iOS 6 with the storyboard mode.
任何人都可以帮助我吗?
Can anyone help me?
推荐答案
您的主要问题是从ClassB 访问ClassA的对象。
Your main problem is to access object of ClassA from ClassB.
这里有很多方法和答案:
Here are a lot of ways, and answers here, to do :
< a href =https://stackoverflow.com/questions/10052594/xcode-update-viewcontroller-label-text-from-different-view> Xcode - 从不同视图更新ViewController标签文本
这篇关于如何在子视图中创建按钮以更新其父视图中的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!