代码之家  ›  专栏  ›  技术社区  ›  mosca1337

uitabar–setItems:动画:崩溃

  •  1
  • mosca1337  · 技术社区  · 15 年前

    所以我有一个在界面生成器中创建的UITabView控制器。在IB中设置了UITABBARTION的标题和图像属性。在XIB中存在一个Tab条控制器对象,并进行所有必要的连接。我可以调用简单的命令,如

    [tabBarController setSelectedIndex:1];

    一切正常,但当我设置“items”属性时,我崩溃了。也许我有内存管理问题?

    下面是崩溃代码:

    NSMutableArray *modifiedItems = [[tabBarController.tabBar items] mutableCopy];  
    [modifiedItems removeObjectAtIndex:2];  
    NSArray *newItems = [[NSArray alloc] initWithArray:modifiedItems];  
    -->[tabBarController.tabBar setItems:newItems animated:NO];  
    

    *由于未捕获的异常“nsInternalConsistencyException”而终止应用程序,原因:“不允许直接修改由选项卡栏控制器管理的选项卡栏。” * 第一次抛出时调用堆栈:

    0   CoreFoundation                      0x02b9bb99 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02ceb40e objc_exception_throw + 47
    2   CoreFoundation                      0x02b54238 +[NSException raise:format:arguments:] + 136
    3   CoreFoundation                      0x02b541aa +[NSException raise:format:] + 58
    4   UIKit                               0x005f7019 -[UITabBar setItems:animated:] + 2037
    5   Zag Map                             0x00003422 -[ZagMapAppDelegate iPodTouchRemoval] + 270
    6   Zag Map                             0x00002eea -[ZagMapAppDelegate applicationDidFinishLaunching:] + 551
    7   UIKit                               0x003faf80 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
    8   UIKit                               0x003fd3b0 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 346
    9   UIKit                               0x004073ec -[UIApplication handleEvent:withNewEvent:] + 1958
    10  UIKit                               0x003ffb3c -[UIApplication sendEvent:] + 71
    11  UIKit                               0x004049bf _UIApplicationHandleEvent + 7672
    12  GraphicsServices                    0x03357822 PurpleEventCallback + 1550
    13  CoreFoundation                      0x02b7cff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x02add807 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x02adaa93 __CFRunLoopRun + 979
    16  CoreFoundation                      0x02ada350 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x02ada271 CFRunLoopRunInMode + 97
    18  UIKit                               0x003fcc6d -[UIApplication _run] + 625
    19  UIKit                               0x00408af2 UIApplicationMain + 1160
    20  Zag Map                             0x00002ca0 main + 102
    21  Zag Map                             0x00002c31 start + 53
        terminate called after throwing an instance of 'NSException'
    

    我的NSArray和NSMutableArray看起来很好,因为它们是直接从正常工作的uitabar中产生的。它返回了三个对象,然后是两个。我希望我只是忽略了一些愚蠢的事情。任何想法我都非常感激。

    3 回复  |  直到 15 年前
        1
  •  2
  •   Ole Begemann    15 年前

    异常消息告诉您到底是什么问题:

    '不允许直接修改由选项卡栏控制器管理的选项卡栏。'

    设置选项卡栏控制器的 viewControllers 取而代之的是财产。

        2
  •  1
  •   mosca1337    15 年前
    NSMutableArray *viewControllersCopy = [[tabBarController viewControllers] mutableCopy];
    [viewControllersCopy removeObjectAtIndex:2];
    NSArray *modifiedViewControllers = [[NSArray alloc] initWithArray:viewControllersCopy];
    [tabBarController setViewControllers:modifiedViewControllers animated:NO];
    
        3
  •  0
  •   Sunil Singh    9 年前

    你可以那样做-

     tabBarController.selectedIndex = 1; // set index according to your requirement
    
    推荐文章