iOS itouch replaceObjectAtIndex导航栏消失

时间:2013-11-04 18:25:28

标签: ios iphone objective-c uinavigationitem

我有一系列非常相似的设备,由一个带有三个标签的applet控制。在每个视图控制器中,我使用导航控制器扩展到每个功能的设置。

第一个标签,即“输入”标签,在这三个设备之间尤其不同,所以当检测到我在设备之间切换时,我在我的应用程序委托中执行以下操作:

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,所以交换一个新的视图控制器,但我的导航栏消失了。

我非常感谢你们能够解决这个问题。 谢谢!

1 个答案:

答案 0 :(得分:0)

好的,经过多次抓挠后,以下修正了它:

我最初使用主窗口的XIB来实例化三个选项卡。 如果您没有执行replaceObjectAtIndex,这可以正常工作。当我做了一个ReplaceObjectAtIndex时,它会丢失导航栏。

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

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

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; //在应用程序启动后覆盖自定义点。

    //输入视图(默认为Crescendo)

    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设置时它为什么不起作用。我可以发誓我曾经在以前的版本上工作过,所以也许有些事情发生了变化,苹果忘了告诉我们。 无论如何,我更喜欢这种方法。这并不是第一次像'向导一样'的编程工具给我带来了帮助,所以也许这会让人有点时间。

相关问题