2011-07-08 25 views
1

我在這我想顯示在左側窗格中的UITabBarController一個TTSplitViewController,通過代碼:這裏TTSplitViewController用的UITabBarController

@implementation SplitAppController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 
     [self setupURLRouting]; 
    } 

    return self; 
} 

- (void)setupURLRouting { 
    [self routePrimaryNavigator]; 
    [self routeDetailsNavigator]; 
} 

- (void)routePrimaryNavigator { 

    TTURLMap* map = self.primaryNavigator.URLMap; 

    // Forward all unhandled URL actions to the right navigator. 
    [map from: @"*" toObject: self selector: @selector(willOpenUrlPath:)]; 
    [map from:@"tt://primary" toViewController:[RootViewController class]]; 
} 

RootViewController的是一個的UITabBarController。但是,我收到以下錯誤:

2011-07-08 08:04:23.739 app[3241:207] -[RootViewController topViewController]: unrecognized selector sent to instance 0x520c060 
2011-07-08 08:04:23.755 app[3241:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController topViewController]: unrecognized selector sent to instance 0x520c060' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x017d95a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x0192d313 objc_exception_throw + 44 
    2 CoreFoundation      0x017db0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x0174a966 ___forwarding___ + 966 
    4 CoreFoundation      0x0174a522 _CF_forwarding_prep_0 + 50 
    5 app        0x000f73ff -[TTSplitViewController updateSplitViewButton] + 176 
    6 app        0x000f75d9 -[TTSplitViewController viewDidAppear:] + 90 
    7 UIKit        0x00ae1fab -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 694 
    8 UIKit        0x00a64e4b -[UIView(Internal) _didMoveFromWindow:toWindow:] + 918 
    9 UIKit        0x00a63a60 -[UIView(Hierarchy) _postMovedFromSuperview:] + 166 
    10 UIKit        0x00a5c750 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1080 
    11 UIKit        0x00a5aaa3 -[UIView(Hierarchy) addSubview:] + 57 
    12 app        0x00083d01 -[TTBaseNavigator setRootViewController:] + 306 
    13 app        0x000841f9 -[TTBaseNavigator presentController:parentController:mode:action:] + 70 
    14 app        0x00084437 -[TTBaseNavigator presentController:parentURLPath:withPattern:action:] + 359 
    15 app        0x00084975 -[TTBaseNavigator openURLAction:] + 1320 
    16 app        0x0000c440 -[appAppDelegate application:didFinishLaunchingWithOptions:] + 848 
    17 UIKit        0x00a2bc89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 
    18 UIKit        0x00a2dd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 
    19 UIKit        0x00a38617 -[UIApplication handleEvent:withNewEvent:] + 1533 
    20 UIKit        0x00a30abf -[UIApplication sendEvent:] + 71 
    21 UIKit        0x00a35f2e _UIApplicationHandleEvent + 7576 
    22 GraphicsServices     0x01fee992 PurpleEventCallback + 1550 
    23 CoreFoundation      0x017ba944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    24 CoreFoundation      0x0171acf7 __CFRunLoopDoSource1 + 215 
    25 CoreFoundation      0x01717f83 __CFRunLoopRun + 979 
    26 CoreFoundation      0x01717840 CFRunLoopRunSpecific + 208 
    27 CoreFoundation      0x01717761 CFRunLoopRunInMode + 97 
    28 UIKit        0x00a2d7d2 -[UIApplication _run] + 623 
    29 UIKit        0x00a39c93 UIApplicationMain + 1160 
    30 app        0x00031342 main + 130 
    31 app        0x00002a75 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

如何解決此問題?

回答

2

似乎你的代碼期望RootViewController成爲UINavigationController的子類。

如果您沒有編寫該代碼,您可以創建一個UINavigationController子類,並使用標籤欄控制器將其初始化爲根視圖控制器,並隱藏導航欄,我認爲這會給出您正在查看的結果對於。

+0

我的答案因爲沒有明顯的原因而被否決 - – EmilioPelaez

+0

Jep。這也適用於我。 – DAS

0

這是正確的

[map from:@"tt://primary" toViewController:[RootViewController class]]; 

我的建議是

[map from:@"tt://primary" toViewController:RootViewControllerobject]; 
2

EmilioPelaez是完全正確的,我只是成功了,像這樣類似的解決方案,和它的作品!

@implementation MainViewController 

- (id)initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query { 
    MainTabBarController *mainTabBarController = [[MainTabBarController alloc] init]; 
    [mainTabBarController setTabURLs:[NSArray arrayWithObjects: 
             @"tt://firstLink", 
             @"tt://secondLink", 
             nil]]; 

    self = [super initWithRootViewController:mainTabBarController]; 
    [mainTabBarController release]; 
    self.navigationBarHidden = YES; 
    return self; 
} 

@end 
0

我找到了另一種方式,使其工作(也許是減少代碼的複雜性更好的辦法):

繼承的UITabBarController這種額外的方法:

- (UIViewController *)topViewController { 
    return self; 
} 

它完美。