Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6801431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:05:57+00:00 2026-05-26T19:05:57+00:00

I am having problem passing value to a IBOutlet property of destinationViewController but it

  • 0

I am having problem passing value to a IBOutlet property of destinationViewController but it works fine on ordinary property see code below

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"NewsCellToDetail"]) {        
    testViewController *viewController = segue.destinationViewController;
    viewController.titleLabel.text = @"test"; // set the IBOutlet label text to something
    NSLog(@"%@",viewController.titleLabel.text); // this will output to nil
    viewController.textTest = @"testing2"; // set the property to something
    NSLog(@"%@", viewController.textTest) // this will output the string testing2
}

This is the code for the header file testviewcontroller.h

#import <UIKit/UIKit.h>
@interface NewsDetailViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) NSString *textTest;
@end

I already synthesize both the property.

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:05:58+00:00Added an answer on May 26, 2026 at 7:05 pm

    I just got the same problem recently. But when I debug it step by step, I find a possible reason. (I’m sorry I’m also new to Objective C, so my following explanation may be not that accurate and professional … My previous background is mainly web development.)

    If you set a breakpoint just after the line you call

    testViewController *viewController = segue.destinationViewController;

    when you build and run the project, you will find that the UITextField property in the destinationViewController is not allocated and initiated (memory is 0x0) at the breakpoint. Meanwhile the NSString property is already allocated and initialised (so you can set its value).

    I think probably UITextfield is a child view, so it only initiates when its parent view (the destination view) is initiated. But NSString is a property that is not associated with any view, so it is allocated and initiated with the view controller which declares it.

    When I do a further test of this, I find a very interesting thing: the second view is loaded during the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender runs. I do a test code like below:

    In the first view controller .m file:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        NSLog(@"1. %@, %@",[segue identifier],segue.destinationViewController);
    
        Scene2Controller *scene2ViewController = [segue destinationViewController];
        [txtScene2 resignFirstResponder];
    
        NSLog(@"2. scene2ViewController: %@", scene2ViewController);
        NSLog(@"3. txtScene1: %@; passValue: %@", [scene2ViewController txtScene1], scene2ViewController.passValue);
        NSLog(@"4. View2: %@; passValue: %@", [scene2ViewController view], scene2ViewController.passValue);
        NSLog(@"5. txtScene1: %@; passValue: %@", [scene2ViewController txtScene1], scene2ViewController.passValue);
    
        //txtScene1 is the UITextfield property I declared in the second view controller
        //txtScene2 is the UITextfield property I declared in the first view controller
        //passValue is the NSString property I declared in the second view controller 
    
    }
    

    In the second view controller .m file:

    - (void)viewDidLoad
    {
        NSLog(@"6. txtScene1: %@; passValue: %@", txtScene1,passValue);
    
    
        [super viewDidLoad];
    
    }
    

    Noticed that I add sequential numbers before NSLog messages. I found the final log result sequence was 1,2,3,6,4,5 rather than 1,2,3,4,5,6. And in log 3, the txtScene1 result was null (not initiated), but after log 4 (the second view was loaded), in log 5, the txtScene1 was NOT null and has been initiated. This suggested that the second view was loaded during the segue performs. So I guess that during the segue transition, the initiation sequence of the second view controller objects would be: second view controller -> NSString property (and other similar properties, like NSInteger, etc.) -> second view -> UITextfield property (and other subview properties).

    So I changed my codes in the first view controller .m file as below:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        Scene2Controller *scene2ViewController = [segue destinationViewController];
        [txtScene2 resignFirstResponder];
    
        if ([scene2ViewController view]) {
            if ([txtScene2.text isEqualToString:@""]) {
                scene2ViewController.txtScene1.text = @"No Value";
            } else {
                scene2ViewController.txtScene1.text = txtScene2.text;
            }
        }
    
    }
    

    This code then works fine and the value is passed directly to the UITextfield property in the second view.

    Hope above explanation is clear and helpful for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this code possible? A stupid question but I am having a problem understanding
I am having a truly bizarre problem with my code here. It works (seemingly)
I am having some problem with my code for Google Script below: When I
Having a very annoying problem with passing data between activities. This is the code
I'm having a problem passing some parameters to a partial. No matter what I've
I am having a problem with views. I have a view and am passing
I'm having a hard time passing values so here is the code: These is
I am having a problem in passing parameters to webservice which except POST data
I am having problem with passing a pointer by reference. This is the method
I'm having a problem passing cookies in ASP.NET to a new URL. I add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.