从 fourthviewcontroller 中的 firstviewcontroller 访问字符串 objective c

Access string from firstviewcontroller in fourthviewcontroller objective c

您好,我可以在 fourthviewcontroller 中访问 firstviewcontroller 中的字符串吗?我使用了以下代码。但是当我去 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

我看到两种方法:

  1. 创建字符串全局变量并从 VC1 及更高版本
    开始设置它 从 VC4 访问它(不是首选)。
  2. 实例化目标时 VC 为变量传递值
    从VC1 -> VC2 -> VC3 -> VC4,这样就可以得到需要的 VC4.
  3. 中的数据