繁体   English   中英

iOS Itouch replaceObjectAtIndex导航栏消失

[英]iOS itouch replaceObjectAtIndex navigation bar disappears

我有一整套的设备非常相似,并由带有三个标签的小程序控制。 在每个视图控制器中,我都使用导航控制器来扩展这些功能中每个功能的设置。

第一个选项卡,即“输入”选项卡,在这三个设备之间尤其不同,因此,当检测到我已在设备之间切换时,我将在应用程序委托中执行以下操作:

if ([self IsCrescendo])
{
    //thirdViewController is really the crescendo'a input view - I need to rename that mess one day
    crescendoInputView = [[ThirdViewController alloc] init : (UIViewController*) currentViewController];
    crescendoInputView.title = [[viewControllers objectAtIndex:INPUT_TAB_INDEX] title];
    crescendoInputView.tabBarItem = [[viewControllers objectAtIndex:INPUT_TAB_INDEX] tabBarItem];
    [viewControllers replaceObjectAtIndex:INPUT_TAB_INDEX withObject:crescendoInputView];
    [crescendoInputView release];
    [self.tabBarController setViewControllers:viewControllers animated:FALSE];

}

if ([self IsSpirito3])
{ // similar to above using obviously a different view controller
}

if ([self IsSonata])
{ // similar to above using obviously a different view controller
}

最初,此应用程序仅控制一个设备,因此当我首次创建该设备时,我在主窗口的XIB中设置了三个选项卡,效果很好。 它默认为原始设备,导航栏完好无损且可以正常工作。 现在有更多设备要控制,我想只使用replaceObjectAtIndex,以便在其中交换新的视图控制器,但导航栏消失了。

我非常感激您可能对此有所了解。 谢谢!

好的,在抓了很多头之后,以下修复了它:

我最初使用主窗口的XIB来实例化三个选项卡。 如果您不执行replaceObjectAtIndex,则此方法会很好地工作。 当我确实执行ReplaceObjectAtIndex时,它将丢失导航栏。

相反,如果您以编程方式实例化选项卡,以及每个选项卡都有其自己的导航控制器,则可以用不受惩罚的方式替换选项卡,而不会丢失导航栏等功能。

  • (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; //应用程序启动后进行自定义的替代点。

    //输入视图(默认为渐强)

    UIViewController * viewController1 = [[[[ThirdViewController alloc] initWithNibName:@“ ThirdView” bundle:nil] autorelease]; UINavigationController * nav1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

    //体积视图

    UIViewController * viewController2 = [[[[SecondViewController alloc] initWithNibName:@“ SecondView” bundle:nil] autorelease]; UINavigationController * nav2 = [[UINavigationController alloc] initWithRootViewController:viewController2];

    //系统视图UIViewController * viewController3 = [[[[FirstViewController alloc] initWithNibName:@“ FirstView” bundle:nil] autorelease]; UINavigationController * nav3 = [[UINavigationController alloc] initWithRootViewController:viewController3]; self.tabBarController = [[[[UITabBarController alloc] init] autorelease]; self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil];

}

不知道为什么从XIB设置时它不起作用。 我可以发誓我可以在以前的版本上使用它,所以也许某些事情发生了变化,而苹果忘了告诉我们。 无论如何,我更喜欢这种方法。 这不是第一次“像奇才”编程工具咬我,所以也许这可以节省一些时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM