在故事板上,视图和传递数据 [英] On storyboards, views and passing data along
问题描述
在我的 Xcode 4.2 故事板中,我有 2 个 UIViewControllers
、This one time
和 In band camp
In my Xcode 4.2 storyboard, i have 2 UIViewControllers
, This one time
and In band camp
- 在
这一次
中,我有一个带有傻名字"的UIButton
- 在
In band camp
中,我有一个带有label"的UILabel
- In
This one time
, i have aUIButton
with "silly name" on it - In
In band camp
, i have aUILabel
with "label" on it
考虑到我们正在处理 2 个独立的类 AND 我们在 Xcode 4.2 中使用 storyboards
(其中设置了视图之间的转换通过 segue)我如何将愚蠢的名字"从视图控制器 This one time
传递到视图控制器 In band camp
中的标签?"
Considering that we're dealing with 2 separate classes AND we're in Xcode 4.2 using storyboards
(where transition between views is setup via a segue) how can i pass "silly name" from view controller This one time
to the label in view controller In band camp
?"
推荐答案
- 将storyboard中segue的标识符设置为AwesomeSegue"
- 实现 prepareForSegue 方法
在方法内部,检查segue的标识符是否与AwesomeSegue"匹配——如果是,使用destinationViewControllerObject
- Set the identifier of segue in storyboard to "AwesomeSegue"
- Implement prepareForSegue method
Inside the method, check if identifier of segue matches "AwesomeSegue" - if yes, use the destinationViewControllerObject
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"AwesomeSegue"]) {
InBandCampViewController *ibcVC = [segue destinationViewController];
ibcVC.yourData = self.someStuff;
}
}
这篇关于在故事板上,视图和传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!