Note that there are some explanatory texts on larger screens.

plurals
  1. POPush View Controller from app delegate in tab bar
    primarykey
    data
    text
    <p>Im trying to display a ViewController, from my openURL function inside my AppDelegate class, but im not having any luck. Ive tried every solution i could find on the internet, im not sure what im doing wrong... please note i have a tabbed application..</p> <p>I dont really want to use <code>self.tabBarController.selectedIndex</code> because I really want to display a custom built controller like so:</p> <pre><code>CategoryTableViewController *controller = nil; NSUInteger catId = 6; NSString *title = @"Cat Title!"; NSManagedObjectContext *inMemoryContext = [xyzclient newContextUsingInMemoryStore:YES]; controller = [[CategoryTableViewController alloc] initWithManagedObjectContext:inMemoryContext]; [(CategoryTableViewController *) controller setParentCategory:catId]; [(CategoryTableViewController *) controller setFilterCategory:NO]; [(CategoryTableViewController *) controller setStopRefresh:YES]; controller.title = title; [self.tabBarController.selectedViewController.navigationController pushViewController:controller animated:YES]; </code></pre> <p>Here is the code ive written:</p> <pre><code>- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSString *scheme = [url scheme]; if ([scheme hasPrefix:@"xyz"]) { //Attempt 1 UINavigationController *searchNavigationController = [self navigationControllerForViewControllerClass:[SearchTableViewController class]]; [self.tabBarController.selectedViewController.navigationController pushViewController:searchNavigationController animated:YES]; //Attempt 2 NSManagedObjectContext *inMemoryContext = [DealsClient newContextUsingInMemoryStore:YES]; SearchTableViewController *controller = [[SearchTableViewController alloc] initWithManagedObjectContext:inMemoryContext]; [self.tabBarController.selectedViewController.navigationController pushViewController:controller animated:YES]; } } - (UINavigationController *)navigationControllerForViewControllerClass:(Class)viewControllerClass { BaseViewController *viewController = [[viewControllerClass alloc] init]; viewController.context = [self managedObjectContext]; UINib *nib = [UINib nibWithNibName:@"BaseNavigationController" bundle:nil]; UINavigationController *navigationController = [[nib instantiateWithOwner:nil options:nil] lastObject]; navigationController.viewControllers = [NSArray arrayWithObject:viewController]; return navigationController; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [super application:application didFinishLaunchingWithOptions:launchOptions]; self.window.rootViewController = self.tabBarController; [DClient setBaseManagedObjectContext:[self managedObjectContext]]; UINavigationController *featuredNavigationController = [self navigationControllerForViewControllerClass:[FeaturedTableViewController class]]; featuredNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Home", nil) image:[UIImage imageNamed:@"tabbar_home"] tag:TabBarTabHome]; UINavigationController *browseNavigationController = [self navigationControllerForViewControllerClass:[CategoryTableViewController class]]; browseNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Browse", nil) image:[UIImage imageNamed:@"tabbar_browse"] tag:TabBarTabBrowse]; UINavigationController *searchNavigationController = [self navigationControllerForViewControllerClass:[SearchTableViewController class]]; searchNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Search", nil) image:[UIImage imageNamed:@"tabbar_search"] tag:TabBarTabSearch]; UINavigationController *messagesNavigationController = [self navigationControllerForViewControllerClass:[MessagesTableViewController class]]; messagesNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Messages", nil) image:[UIImage imageNamed:@"tabbar_messages"] tag:TabBarTabMessages]; UINavigationController *cartNavigationController = [self navigationControllerForViewControllerClass:[CartTableViewController class]]; cartNavigationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Cart", nil) image:[UIImage imageNamed:@"tabbar_cart"] tag:TabBarTabCart]; NSArray *viewControllers = [NSArray arrayWithObjects:featuredNavigationController, browseNavigationController, searchNavigationController, messagesNavigationController, cartNavigationController, nil]; [self.tabBarController setViewControllers:viewControllers animated:NO]; [xyzEngine setTabBarController:self.tabBarController]; [self.tabBarController setCartBadgeValue:[xyz numItemsInCart]]; NSLog(@"Loaded the page...."); return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload