Hadleigh Gaudreau
Hadleigh Gaudreau

Reputation: 35

Xcode Segue push to Label

I'm having a small problem with my push segue on Xcode Im trying to push the content of one label to another one on a different view controller, this is my current setup no errors are present and but the text on the other view controller doesn't change to match the previous window.

The first example below is my detailviewcontroller which I'm sending the information from. I have created the push segue between the detail view controller and my new view controller which is CODEVIEW and given the segue the name ShowCode.

I was wondering if I was missing line of code which would automatically activate this segues information without the need of a button but instead works when loaded.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{


if ([[segue identifier] isEqualToString:@"ShowCode"]) {


   CODEVIEW  *CodeSender = [segue destinationViewController];

    CodeSender.CODElabel.text = _Code.text;



}
}

Label outlet for CODEVIEW

@property (strong, nonatomic) IBOutlet UILabel *CODElabel;

Label outlet for detail view controller

@property (strong, nonatomic) IBOutlet UILabel *Code;

Upvotes: 0

Views: 166

Answers (1)

Konstantinos
Konstantinos

Reputation: 101

In your current VC:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"ShowCode"]) {
       CODEVIEW  *CodeSender = [segue destinationViewController];
       CodeSender.codeLabeltext = _Code.text;
    }
}

In your target/next VC:

a) inside CODEVIEW.h interface:

@property (strong, nonatomic) NSString *codeLabeltext;
@property (strong, nonatomic) IBOutlet UILabel *CODElabel;

b) in your CODEVIEW.m implementation:

- (void)viewDidLoad {
    [super viewDidLoad];
    //...
    _CODElabel.text = codeLabeltext;
    //...
}

Upvotes: 1

Related Questions