开发者

TTSplitViewController with UITabBarController

I have a TTSplitViewController in which I am trying to show a UITabBarController at the left pane, via the code:

@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 {

    TTU开发者_如何转开发RLMap* 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 here is a UITabBarController. However, I am getting the following error:

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'

How do I fix this?


Seems like your code is expecting RootViewController to be a subclass of UINavigationController.

If you didn't write that code, you can make a UINavigationController subclass, and initialize it with your tab bar controller as a root view controller, and hide the navigation bar, I think this would give the results you are looking for.


EmilioPelaez is quite right, I just succeeded with a similar solution like this, and it works!

@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


I found another way to make it work (and maybe the better way that reduce code complexity):

inherit UITabBarController with this additional method:

- (UIViewController *)topViewController {
   return self;
}

It works perfectly.


is this right

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

my suggestion is

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜