【问题标题】:Switching between a UITabBarController and a UIViewController (iOS Xcode)在 UITabBarController 和 UIViewController (iOS Xcode) 之间切换
【发布时间】:2012-01-02 10:20:33
【问题描述】:

我已经花了很长时间停留在这个问题上:使用选项卡栏模板(没有情节提要)我可以轻松地在选项卡之间切换并在每个表中的视图之间切换,但是在 UITabBarController 和 @987654322 之间切换时@我一直尝试的任何代码都行不通。

-(IBAction)tabtoview:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                           forView:self.view
                             cache:YES];
    [self.tabBarController removeFromParentViewController];   
    [self.view addSubview:self.mainscreen]; //Crashes here
    [UIView commitAnimations];
}

与其删除tabBarController,不如在动画后隐藏/禁用它。感谢任何帮助!

【问题讨论】:

  • 崩溃时的错误信息是什么?
  • SIGABRT - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController superview]: unrecognized selector sent to instance 0x6dae9f0'

标签: iphone objective-c ios cocoa-touch uiviewcontroller


【解决方案1】:

我认为您的问题是 UITabBarControllerUINavigationController 是那些无法按照您的方式处理的控制器。

您最好将您的UIWindow 子类化为app delegate,并将-(IBAction)tabtoview:(id)sender; 方法移动到UIWindow 的子类中。我试过了,效果很好。

原因是,你必须有一个控制器来负责切换视图。您要做的是交换控制器,而不是视图。这是一个冲突。标签是UITabController 的一部分,它们不是视图! UINavigationController 也是如此。

因此,如果您只是简单地交换视图,您可以在其中一个 viewController 中直接进行,但是将控制器与另一个控制器(即 UIViewcontrollerUITabBarController)交换应该在更高级别进行处理,即应用程序委托.该级别中唯一可用的实例是您的UIWindow

【讨论】:

    【解决方案2】:

    为什么不使用

    UIView *v = [[UIView alloc] initWithFrame:[[UIApplication mainScreen] bounds]];  
    [self presentModalViewController:v animated:YES];
    

    我觉得应该可以

    【讨论】:

      猜你喜欢
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 2011-11-02
      • 1970-01-01
      • 2015-03-20
      相关资源
      最近更新 更多