objective-c - xcode View 被调用并初始化但未显示

标签 objective-c ios xcode cocoa-touch uiview

我在显示 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];

}

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

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

关于objective-c - xcode View 被调用并初始化但未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7778369/

相关文章:

objective-c - ios - 在子类化时从 UIPickerView 传递值

ios - ios 应用程序中所有 View Controller 的相同按钮

ios - iOS 上使用 Google 跟踪代码管理器的非屏幕浏览事件

ios - 在 ios 中使用 LongGestureRecognizer 更改 View 选定部分的颜色

iphone DatePickerView - PickerView - 模态视图还是弹出窗口?什么是最好的?

ios - UIView 上存在哪些类似的功能方法(viewWillAppear)?

ios - 仅将 Y 轴粘贴在 Google 实时图表上的一个位置

ios - 操作无法完成 IDETemplateParseError error1

objective-c - 应用从应用商店返回设备 token 的空值

iphone - 如何在 UITableViewCell 自动换行中制作文本?