0

Hi can I access a string from firstviewcontroller in fourthviewcontroller. I used following code. But when I go to the fourthviewcontroller string is null.

firstviewcontroller.m
#import "Fourthviewcontroller.h"

Fourthviewcontroller view = [[Fourthviewcontroller alloc] init];
view.devInText = devInput.text; //devInput is a UItextfield
NSLog(@"%@",view.devInText); // output is correct 

fourthviewcontroller.h
@property (nonatomic, strong) NSString *devInText;

fourthviewcontroller.m
NSLog(@"%@",_devInText); // output displays null
5
  • You are alloc and initialize your view so that's why it is always null Commented Sep 12, 2017 at 6:18
  • Do one one thing Compare , NSLog(@"%@", view) and self (in fourthviewcontroller.h) and let me know what is difference Commented Sep 12, 2017 at 6:19
  • You are navigating from firstviewcontroller to fourthviewcontroller ?? Commented Sep 12, 2017 at 6:20
  • Show more code, How you are navigating from firstviewcontroller to fourthviewcontroller? Commented Sep 12, 2017 at 6:36
  • 1
    Best way is use singleton design pattern galloway.me.uk/tutorials/singleton-classes Commented Sep 12, 2017 at 7:12

1 Answer 1

1

I see two approaches:

  1. Make the string Global variable and set it from VC1 and later on
    access it from VC4 (not preferred).
  2. While instantiating destination VC pass value for variable
    from VC1 -> VC2 -> VC3 -> VC4, in this way you can get the required data in VC4.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.