I have a iOS single-view application for the iPad and using storyboards.
-
I have the default viewcontroller created by xcode (vc1). I
place a button on its view. -
I then drag a new view controller (screen2VC) onto the
storyboard. -
I also create a new view controller subclass (vc2SubClass)
-
I associate screen2VC to this subclass via the identity inspector.
-
On screen2VC’s view, I have a label. I control-drag the label onto
vc2SubClass to create an outlet. -
I create a segue between vc1’s button and vc2’s button.
-
In performSegue override i have the following code:
if ([segue.identifier isEqualToString:@"segue1"])
{
screen2VC* vc = [segue destinationViewController];
vc.label1.text = @"screen 2";
}
When I run the code and press the button, the segue works and transitions between the two views just fine, but screen2VC’s label is never set to ‘screen 2’. As a test, I placed the label1.text = @"screen 2"; code into vc2SubClass, but that made no difference. It seems there’s still no association between screen2VC and vc2SubClass, even though the former is subclassing the latter and the label is pointing to a UILabel outlet.
Any ideas?
When you’re in
performSegue:of vc1, vc2’s view hierarchy has not yet been set up. The normal way of doing this is to have a property in vc2 that temporarily is given the string duringperformSegue:. This property is then used to update the label in vc2’sviewWillAppear:.(When you say “As a test, i placed the ‘label1.text = @”screen 2″;’ code in vc2SubClass but that makes no difference” I’m not sure what’s going on there. What method was that code put into?)