Objective c 调用并初始化了xcode视图,但未显示

Objective c 调用并初始化了xcode视图,但未显示,objective-c,ios,xcode,cocoa-touch,uiview,Objective C,Ios,Xcode,Cocoa Touch,Uiview,我在显示视图时遇到问题。在当前视图中按下按钮时,将执行以下操作: - (IBAction) vistaUser: (id)sender{ loginTabController *theInstance = [[loginTabController alloc] init]; [theInstance logIn:user.text :password.text]; } 然后,调用下面的logIn函数,该函数必须显示userviewcontroller视图,但未显示。视图保持

我在显示视图时遇到问题。在当前视图中按下按钮时,将执行以下操作:

- (IBAction) vistaUser: (id)sender{

    loginTabController *theInstance = [[loginTabController alloc] init];
    [theInstance logIn:user.text :password.text];

}
然后,调用下面的
logIn
函数,该函数必须显示
userviewcontroller
视图,但未显示。视图保持为当前视图。但是,
userViewController
视图已初始化,并从此视图执行
getData
函数!我不明白为什么不显示调用的视图!谢谢你的帮助

- (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的视图。因此,当您将UserViewController的视图添加到tabViewController的视图时,它不会做任何事情。试试这个:

- (IBAction) vistaUser: (id)sender{

    loginTabController *theInstance = [[loginTabController alloc] init];
    [self.view addSubview:theInstance.view];
    [theInstance logIn:user.text :password.text];

}
这应该可以让它正常工作,但您可能需要解决一些常规代码设计问题:

  • 在UIView中使用较新的块动画功能,而不是较旧且更难的“beginAnimations”“Committeanimations”方法
  • 调用立即调用另一个viewController的viewController是没有意义的。跳过loginTabController,直接转到userViewController。如果出于某种原因,您希望保留loginTabController作为单独类使用的代码,那么就不要使用viewController子类