Nguyen Tho
Nguyen Tho

Reputation: 99

Pass data forward by Segue (objective-c)

I have 2 view controller

  1. Main has a button

  2. Detail has a label: lblDetail

I'm trying to pass data by segue : "sgPushDetail". When click on the button on Main, the label on Detail will be changed.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"sgPushDetail"]) {    
        DetailViewController *detail = segue.destinationViewController;
        detail.lblDetail.text = @"you've already clicked";   
    }        
}

But when i build, the label doesn't change. Please help me with this case!

Upvotes: 0

Views: 165

Answers (1)

rshankar
rshankar

Reputation: 3085

The DetailViewController is not loaded when you are setting value for the label in prepareForSegue method. Do the following:

  1. Create a property (i.e. NSString) in DetailViewController
  2. Set the value for this property in prepareForSegue method
  3. In viewDidLoad method of your DetailViewController, assign this property value to the label.

Upvotes: 1

Related Questions