Frage

So habe ich einen UITabView Controller, der in Interface Builder erstellt wurde. Die Titel und Bildeigenschaften von UITabBarItem wurden in IB gesetzt. Ein Tab Bar-Controller-Objekt ist in der xib und alle notwendigen Verbindungen hergestellt werden. Ich bin in der Lage einfache Befehle zu nennen wie

[TabBarController SetSelectedIndex: 1];

funktioniert alles einwandfrei, aber wenn ich die ‚Elemente‘ Eigenschaft, ich abstürzen. Vielleicht ein Speicherverwaltung Problem, das ich habe?

Hier ist das Krachen Code:

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

* Beenden app aufgrund nicht abgefangene Ausnahme ‚NSInternalInconsistencyException‘ Grund: ‚Direkt eine Tab-Leiste durch eine Tab-Leiste Controller verwaltet Modifikation ist nicht erlaubt‘ * Anrufstapel auf dem ersten Wurf:

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'

Meine NSArray und NSMutableArray erscheinen in Ordnung zu sein wenn man bedenkt sie gerade aus dem funktionierenden UITabBar kam. Er kehrte drei Objekte, dann zwei. Ich hoffe, dass ich mit Blick auf etwas einfach nur dumm hier. Irgendwelche Ideen Ich würde wirklich zu schätzen wissen.

War es hilfreich?

Lösung

Die Ausnahmemeldung sagt Ihnen genau, was falsch ist:

  

‚Direkt eine Tab-Leiste durch eine Tab-Leiste Controller verwaltet Modifikation ist nicht erlaubt.‘

Stellen Sie die Tab-Leiste Controller viewControllers Eigenschaft statt.

Andere Tipps

NSMutableArray *viewControllersCopy = [[tabBarController viewControllers] mutableCopy];
[viewControllersCopy removeObjectAtIndex:2];
NSArray *modifiedViewControllers = [[NSArray alloc] initWithArray:viewControllersCopy];
[tabBarController setViewControllers:modifiedViewControllers animated:NO];

Sie können wie das tun -

 tabBarController.selectedIndex = 1; // set index according to your requirement
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top