我试图在两个视图控制器之间移动一个 NSString 并且在搜索了所有复杂的方式之后,我想习惯的最简单和最直接的方式是在接收 VC 中编写一个 initWithName 函数并在发送中调用它风险投资。它确实成功地移动了它,但我希望它在 ViewDidLoad 加载 textViewer 之前执行,以便在按下选项卡按钮后立即显示。这是来自发送 VC 的代码:
- (void)textViewDidEndEditing:(UITextView *)textView
{
if ([textView.text isEqualToString: @""]) {
textView.text = @"*Paste the machine code in question here*";
}
SecondViewController *theVCMover = [[SecondViewController alloc] initWithName: textView.text];
[self.navigationController pushViewController:theVCMover animated:YES]; //Is this really necessary if I'm not going to segue it directly, I'm just waiting for the user to press the next tab
gotItLabel.text = @"Got it! Ready for action...";
}
这是接收VC的代码:
- (id)initWithName:(NSString *)theVCMovee {
self = [super initWithNibName:@"SecondViewController" bundle:nil];
if (self) {
rawUserInput = theVCMovee;
CleanerText.text = rawUserInput;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
CleanerText.text = rawUserInput;
NSLog(@"Got the other tab's text and it's %@ ", rawUserInput);
}