Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Luke Terzich
Luke Terzich
5,193 Points

Passing variables from -viewWillAppear to an IBAction not working (URGENT)

Hello guys, i have a searchUserViewController which has a textfield and the current user types in a user to search, the variable is passed to my customSearchedViewController and i can NSLOG it in the ViewWillAppear, everything works WAHOO

However, i have a textfield on this page and a button with an IBAction to upload the message in the textview to parse.com with the details from the sender and receiver if that makes sense?

long story short - I can call the variable from the ViewWillApper but as soon as i hit the button the app crashes and the variable is NULL!

Why is my variable NULL in the IBAction? i am using

    if([segue.identifier isEqualToString:@"customUserDetails"])
            NSString *userID = usernameID;
            customSearchViewController *vc = [segue destinationViewController];
            vc.userIDnew = userID;

to send the variable across viewControllers... What makes this even weirder is that it only crashes on my phone, on the simulator it works fine and it is not null!

1 Answer

Stone Preston
Stone Preston
42,016 Points

where do you declare usernameID? is that a property?