我想两个视图控制器之间以及周围的一切令人费解的方式,我想习惯的最简单,最直接的方式搜索后移至一个NSString是写在接受VC的initWithName函数和调用它发送VC。它确实成功地移动了它,但是我希望它在ViewDidLoad加载textViewer之前执行,以便它在按下Tab键后立即显示。下面是从发送VC代码:在ViewDidLoad之前执行InitWithName可能吗?
- (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代码:你不能(可靠)上的一个实例调用方法直到init
执行完毕
- (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);
}
视图加载后'viewDidLoad'被调用,该视图第一次加载的东西尝试访问它,就像调用'viewController.view',或有一个父视图控制器布局它的子(或窗口显示其根视图控制器的视图)。所以只要你不尝试自己访问'view'属性,并且屏幕上还没有布局,你应该可以安全地设置你需要的所有参数,然后调用'viewDidLoad'(即'init ...'和'push ...' – Guillaume 2013-03-25 16:52:52
您是否正在使用自动引用计数(ARC),以及如何定义'rawUserInput'(我们可以看到.h?) – NSGod 2013-03-25 16:54:56
是的,使用ARC,在这里你去: “@property(强,非原子)的NSString * rawUserInput;” – 2013-03-25 17:42:55