Q:

Segue Won't Pass on Data

So I set up a segue from one UIViewController to another (MenuViewController to AgendaViewController), but the variable on the target UIViewController still shows up as null, even though I updated it during the segue.
Am I doing something wrong in the segue method?
This is the code for MenuViewController, the view I am trying to segue FROM:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"toAgenda"]){
    AgendaViewController *controller = (AgendaViewController *)segue.destinationViewController;

    // Load agenda url based on event's name
    PFQuery *event_query = [PFQuery queryWithClassName:@"Event"];
    [event_query whereKey:@"event_name" equalTo:event_name];
    [event_query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            for (PFObject *object in objects) {
                controller.agenda_url = (NSString*)[object objectForKey:@"event_agenda_url"];
                NSLog(@"%@", [object objectForKey:@"event_agenda_url"]);
            }
        } else {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
    }
}

This is the code I have for the target view controller, AgendaViewController:
#import "AgendaViewController.h"
#import "Parse/Parse.h"

@interface AgendaViewController ()

@end

@implementation AgendaViewController

@synthesize agenda_url;
@synthesize webView;

- (void)viewDidLoad
{
[super viewDidLoad];

// Load web view with agenda url, which was just retrieved
NSURL *url =[NSURL URLWithString:agenda_url];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[webView loadRequest:request];

NSLog(@"Data recieved. Agenda_url = %@", agenda_url);
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { }
return self;
}

@end

Thanks!

A:

For me it looks like it is null because you are assigning agenda_url value on the second thread. So basically AgendaViewController viewdidload method is triggered before completion block from findObjectsInBackgroundWithBlock: is executed. To fix that you should either assign agenda_url on the main thread or call loadRequest: in completion block
 [event_query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        for (PFObject *object in objects) {
            controller.agenda_url = (NSString*)[object objectForKey:@"event_agenda_url"];
            NSLog(@"%@", [object objectForKey:@"event_agenda_url"]);
        }
        NSURL *url =[NSURL URLWithString:controller.agenda_url];
        NSURLRequest *request=[NSURLRequest requestWithURL:url];
        [controller.webView performSelectorOnMainThread:@selector(loadRequest:) withObject:request waitUntilDone:NO];
    } else {
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];

Just edited code above to perform loadRequest on main thread. As suggested in comment below it is not safe to call UIKit element on background thread. 

