xcode视图被调用并初始化但未显示

时间:2011-10-15 14:20:13

标签: objective-c ios xcode cocoa-touch uiview

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

- (IBAction) vistaUser: (id)sender{

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

}

然后,调用logIn函数后,必须显示userViewControler视图,但不显示。查看保持当前状态。但是,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];

}

1 个答案:

答案 0 :(得分:1)

您永远不会显示您的loginTabController视图。因此,当您将UserViewController的视图添加到tabViewController的视图时,它不会执行任何操作。试试这个:

- (IBAction) vistaUser: (id)sender{

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

}

这应该让它工作,但是您可能想要解决一些常见的代码设计问题:

  1. 在UIView中使用较新的块动画功能,而不是旧的和更困难的“beginAnimations”“commitAnimations”方法。
  2. 调用立即调用另一个viewController的viewController是没有意义的。跳过loginTabController,直接进入userViewController。如果由于某种原因你想保留loginTabController作为一个单独的类使用的代码,那就不要使用viewController子类。