【问题标题】:xcode view is called and initialized but not shown调用并初始化 xcode 视图但未显示
【发布时间】:2011-12-08 08:48:10
【问题描述】:

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

- (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];

}

【问题讨论】:

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


    【解决方案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 子类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多