我知道这个问题被问了大约 100 次,但我就是不知道我做错了什么。
这是我的第二个 iOS 应用。我想通过按下 ViewControllerA 中的按钮来修改 ViewControllerB 中的标签。
- 我在 Storyboard 中从我的 Button (
ViewControllerA
) 到 my制作了一个 Segue,ViewControllerB
并将其命名为“TestSegue”。 - 写
#import "ViewControllerB.h
在我的ViewControllerA.h
- 我在 ViewControllerA.m 中编写了这段代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"TestSegue"]){
ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
controller.TestLabel.text = @"TEST!";}}
In my ViewControllerB nothing happens with the TestLabel...
Can anybody see what I did wrong?
Thanks in advance
Edit:
Works now thanks to rpledge.
New Code:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"TestSegue"]){
ViewControllerB *controller = (ViewControllerB *)segue.destinationViewController;
controller.TestString = @"TEST!";}}