我在显示 View 时遇到问题。当在当前 View 中按下按钮时,将执行以下操作:
- (IBAction) vistaUser: (id)sender{
loginTabController *theInstance = [[loginTabController alloc] init];
[theInstance logIn:user.text :password.text];
}
然后,调用以下 logIn
函数,该函数必须显示 userViewControler
View ,但未显示。 View 仍为当前 View 。但是,userViewController
View 已初始化,并且该 View 中的 getData
函数被执行!我不明白为什么调用的 View 不显示!感谢您的帮助!
- (void)logIn: (NSString *)strUser: (NSString *)strPass
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
if (self.controladorUser == nil)
{
userViewController *aController = [[userViewController alloc] initWithNibName:@"userViewController" bundle:nil];
self.controladorUser = aController;
[aController release];
}
[UIView setAnimationTransition: UIViewAnimationOptionCurveEaseIn forView:self.view cache:YES];
[self.controladorPass viewWillDisappear:YES];
[self.controladorUser viewWillAppear:YES];
[self.controladorPass.view removeFromSuperview];
[self.view insertSubview:controladorUser.view atIndex:0];
[self.controladorPass viewDidDisappear:YES];
[self.controladorUser viewDidAppear:YES];
[UIView commitAnimations];
//getData call
userViewController *theInstance = [[userViewController alloc] init];
[theInstance getData:strUser :strPass];
}
最佳答案
你永远不会显示你的loginTabController的 View 。因此,当您将 UserViewController 的 View 添加到 tabViewController 的 View 时,它不会执行任何操作。试试这个:
- (IBAction) vistaUser: (id)sender{
loginTabController *theInstance = [[loginTabController alloc] init];
[self.view addSubview:theInstance.view];
[theInstance logIn:user.text :password.text];
}
这应该可以让它工作,但是您可能需要解决一些常规代码设计问题:
- 在 UIView 中使用较新的 block 动画函数,而不是较旧且更困难的“beginAnimations”“commitAnimations”方法。
- 调用一个立即调用另一个 viewController 的 viewController 是没有意义的。跳过loginTabController,直接进入userViewController。如果出于某种原因你想保留 loginTabController 用作单独的类的代码,那也可以,只是不要使用 viewController 子类。
关于objective-c - xcode View 被调用并初始化但未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7778369/