Hedam
Hedam

Reputation: 2249

Passing values between views gives (null)

I'm trying to pass some values from a view to another, but the values are always (null). Here my code.

First:

[self performSegueWithIdentifier:@"Thanks" sender:self];

Then:

-(void)prepareForSegue:(UIStoryboardSegue *)segue
{
    ThanksViewController *vc = [segue destinationViewController];
    [vc set_event_image_url:[NSString stringWithFormat:@"bla bla bla %@.png", event_id]];
    [vc set_event_name:eventTitle];        
}

In the receiver I'm initiating the variables.

@property(nonatomic,copy) NSString* _event_name;
@property(nonatomic,copy) NSString* _event_image_url;

AND

@synthesize _event_image_url;
@synthesize _event_name;

The values are now (null). Any Ideas why it fails? The segue is added to the storyboard too.

Upvotes: 0

Views: 59

Answers (1)

James Frost
James Frost

Reputation: 6990

I would remove the underscores from your property names - it's not the standard way of naming things in objective-c and it's just possible that it could be confusing things (cocoa by default will synthesise you instance variables that begin with an underscore).

@property(nonatomic,copy) NSString* eventName;
@property(nonatomic,copy) NSString* eventImageUrl;

You can also remove your synthesize statements - objective-c will do your synthesizing for you, so they're not necessary.

You would then call [vc setEventTitle:blah];

However, the main issue is that you've implemented prepareForSegue incorrectly! The proper method signature should be:

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

Add the sender parameter and you should find it'll be called.

Upvotes: 1

Related Questions