Steblo
Steblo

Reputation: 625

How to set label text in one scene from a different view controller

I am reading the Sam's Xcode in 24 hours and am practising segues. I have started one segue using the following code:
But I am finding that the text in my label in my destination view is not being set. Yet I have created an outlet for it in my NewSceneViewController.

 - (IBAction)startSegue:(id)sender {  
     [self performSegueWithIdentifier:@"toNewScene" sender:sender];     
    }  

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {  
    ViewController *startingViewController;  
    NewSceneViewController *myDestinationViewController;  

    startingViewController=(ViewController *)segue.sourceViewController;  

    myDestinationViewController=(NewSceneViewController *)segue.destinationViewController;  
    myDestinationViewController.myLabel.text=@"HI";
    }

Upvotes: 1

Views: 3165

Answers (1)

DoS
DoS

Reputation: 1474

so im scrapping my previous answer...i was playing around and found that you can actually set a uilabels text...get this...after! you present a modal view controller.

ModalViewController *modalVC = [ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];

modalVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentModalViewController:modalVC animated:YES];

modalVC.someLabel.text = @"what ever text you want...";

go figure. this can probably be done with storyboards as well but would need to manually override the prepareForSegue: & performSegueWithIdentifier: methods.

Upvotes: 1

Related Questions