I have this code in my app delegate:
- (void) refreshTabBar{
if(mainTabBarController){
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:#"Page1" image:[UIImage imageNamed:#"1_icon.png"] tag:3];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:#"Page2" image:[UIImage imageNamed:#"2_icon.png"] tag:1];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:#"Page3" image:[UIImage imageNamed:#"3_icon.png"] tag:2];
UITabBarItem *tab4 = [[UITabBarItem alloc] initWithTitle:#"Page4" image:[UIImage imageNamed:#"4_icon.png"] tag:4];
UITabBarItem *tab5 = [[UITabBarItem alloc] initWithTitle:#"Page5" image:[UIImage imageNamed:#"5.png"] tag:0];
[[[mainTabBarController viewControllers] objectAtIndex:3] setTabBarItem:tab1];
[[[mainTabBarController viewControllers] objectAtIndex:1] setTabBarItem:tab2];
[[[mainTabBarController viewControllers] objectAtIndex:2] setTabBarItem:tab3];
[[[mainTabBarController viewControllers] objectAtIndex:4] setTabBarItem:tab4];
[[[mainTabBarController viewControllers] objectAtIndex:0] setTabBarItem:tab5];
//reload the ClaimViewController
//[[[[[mainTabBarController viewControllers] objectAtIndex:2] childViewControllers] objectAtIndex:0] reloadView];
NSLog(#"setting selected tabbar controller index to 2");
mainTabBarController.selectedIndex = 2;
[mainTabBarController setSelectedIndex:2];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
mainTabBarController = [[UITabBarController alloc] init];
UIViewController *viewController = nil;
viewController = [storyboard instantiateViewControllerWithIdentifier:#"SplashScreenViewController"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
//initialize objects
facebookNetworkController = [[FacebookNetworkController alloc]init];
//UI cutomizations
[self applyTheme];
//TestFlight SDK
[TestFlight takeOff:#"xxxxxxxxxxx-xxxxxxxx-xxxxxxxxx-xxxxxxx"];
// Let the device know we want to receive push notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
// ------ GOOGLE ANALYTICS ------- \\
// Optional: automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;
// Optional: set Google Analytics dispatch interval to e.g. 20 seconds.
[GAI sharedInstance].dispatchInterval = 20;
// Optional: set Logger to VERBOSE for debug information.
[[[GAI sharedInstance] logger] setLogLevel:kGAILogLevelNone];
// Initialize tracker.
tracker = [[GAI sharedInstance] trackerWithName:#"YOYOYOYOYOYO" trackingId:#"UA-43403680-1"];
// NEW RELIC
[NewRelicAgent startWithApplicationToken:#"a6a6a6a6a6a6a6a6a6a6as6as6a6a6"];
[self refreshTabBar];
NSLog(#"Application did finish launching");
return YES;
}
For some reason it does not select this index.
What am I doing wrong?
[[mainTabBarController tabBar] setSelectedItem:[[[mainTabBarController tabBar] items] objectAtIndex:2]];
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
You can use [mainTabBarController setSelectedIndex:2];
Let this work be done by controller of tab bar.
Related
I'm working on a very old project that was done with the bare minimum of NIBS.
I've added the new Default images so that the screen now loads to iPhone5 size as confirmed when I see the image on the iPhone5 Simulator.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[self.window setFrame:[[UIScreen mainScreen] bounds]];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults)
{
if ([[standardUserDefaults stringForKey:#"user"] caseInsensitiveCompare:#"(null)"] == NSOrderedSame)
{
//NSLog(#"Setting user to default_user");
[standardUserDefaults setObject:#"default_user" forKey:#"user"];
[standardUserDefaults setObject:#"default_user" forKey:#"password"];
[standardUserDefaults setObject:#"NO" forKey:#"logged_in_status"];
[standardUserDefaults synchronize];
}
}
UINavigationController *localNavigationController;
self.tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4];
SettingsVC *firstViewController;
firstViewController = [[SettingsVC alloc] init];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[localNavigationController.tabBarItem initWithTitle:#"Settings" image:[UIImage imageNamed:#"icn_new_request.png"] tag:1];
firstViewController.navigationItem.title=#"Settings";
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[firstViewController release];
VideoMenuVC *secondViewController;
secondViewController = [[VideoMenuVC alloc] init];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[localNavigationController.tabBarItem initWithTitle:#"Video" image:[UIImage imageNamed:#"icn_existing.png"] tag:2];
secondViewController.navigationItem.title=#"Video";
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[secondViewController release];
LoginVC *thirdViewController;
thirdViewController = [[LoginVC alloc] init];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
[localNavigationController.tabBarItem initWithTitle:#"Log On/Off" image:[UIImage imageNamed:#"icn_phone.png"] tag:3];
thirdViewController.navigationItem.title=#"Log On/Off";
[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[thirdViewController release];
self.tabBarController.viewControllers = localControllersArray;
self.tabBarController.selectedIndex = 1;
[localControllersArray release];
self.user_name = [[NSString alloc ]init];
self.user_name = #"defaultFolder";
NSLog(#"Frame Height: %f",self.window.frame.size.height);
NSLog(#"Tab Height: %f",self.tabBarController.view.frame.size.height);
NSLog(#"Tab Origin Y: %f",self.tabBarController.view.frame.origin.y);
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
When the Launch image appears it takes up the full area of the iPhone 5 Simulator screen.
When the app loads in fully and VideoMenuVC is displayed you can see that it is not using the full area. The white area under the tabbar should not be there.
Though looking at the NSLogs of the views height they seem correct.
I've been looking at this for a couple of hours and maybe I cant see the obvious because I'm looking too hard. I'd appreciate some fresh eyes/ideas as to what I've done wrong.
Many Thanks,
Code
There is nothing found in your code which can cause this. I will recommend to check the size of the icon-images. In one of my project, I have used images of 60 * 60 or 70 * 60 pixels.
I am creating a View Controller that only appears the first time the user opens the app. I had it working by just pushing the welcome view controller, but then I couldn't get it to push the normalViewController when the user was done in the welcomeViewController. I then then tried to set the welcomeViewController as the rootViewController. This still shows the welcomeScreen, but all of the buttons on it do not work. If any one knows how to fix this or a better way to create a welcomeViewController, it would be very much appreciated. Here is the code I am using to show the rootViewController
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]){
NSLog(#"Second time opening the app");
}
else{
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[[UIApplication sharedApplication] keyWindow].rootViewController = welcomeViewController;
}
To create the UITabBar -
self.tabBarController = [[UITabBarController alloc] init];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// FeedViewController
feedViewController=[[FeedViewController alloc] init];
feedViewController.tabBarItem.image=[UIImage imageNamed:#"Describe Home_Icon_NormalArtboard-1"];
feedViewController.title = #"Timeline";
feedViewController.tabBarItem.title = nil;
//TodayViewController
TodayViewController *todayViewController = [[TodayViewController alloc] init];
todayViewController.tabBarItem.image = [UIImage imageNamed:#"Today_Icon"];
todayViewController.title = #"Today";
todayViewController.tabBarItem.title = nil;
//CreateViewController
self.createViewController = [[CreateViewController alloc] init];
self.createViewController.tabBarItem.image = [UIImage imageNamed:#"Create_Icon"];
self.createViewController.title = #"Create";
self.createViewController.tabBarItem.title = nil;
//AlertViewController
AlertsViewController *alertsViewController = [[AlertsViewController alloc] init];
alertsViewController.tabBarItem.image=[UIImage imageNamed:#"Alerts_IconArtboard-1"];
alertsViewController.title=#"Alerts";
alertsViewController.tabBarItem.title = nil;
//ProfileViewController
ProfileViewController *profileViewController = [[ProfileViewController alloc] init];
profileViewController.tabBarItem.image=[UIImage imageNamed:#"Profile_IconArtboard-1"];
profileViewController.title=#"Profile";
profileViewController.tabBarItem.title = nil;
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2];
self.tabBarController = [[UITabBarController alloc] init];
UINavigationController *feedNavigationController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[tabBarViewControllers addObject:feedNavigationController];
feedNavigationController = nil;
UINavigationController *todayNavigationController = [[UINavigationController alloc] initWithRootViewController:todayViewController];
[tabBarViewControllers addObject:todayNavigationController];
todayNavigationController = nil;
UINavigationController *createNavigationController = [[UINavigationController alloc] initWithRootViewController:self.createViewController];
[tabBarViewControllers addObject:createNavigationController];
createNavigationController = nil;
UINavigationController *alertsNavigationController = [[UINavigationController alloc] initWithRootViewController:alertsViewController];
[tabBarViewControllers addObject:alertsNavigationController];
alertsNavigationController = nil;
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profileViewController];
[tabBarViewControllers addObject:profileNavigationController];
profileNavigationController = nil;
self.tabBarController.viewControllers = tabBarViewControllers;
tabBarViewControllers = nil;
[self.window addSubview:self.tabBarController.view];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"TermsAccepted"]){
NSLog(#"Second time opening the app");
rootViewController = // Your new main controller
}
else
{
rootViewController = // Terms and conditions view controller
}
self.window.rootViewController = rootViewController;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = navigationController;
return YES;
}
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..
I dont really want to use self.tabBarController.selectedIndex because I really want to display a custom built controller like so:
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];
Here is the code ive written:
- (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;
}
Ok I'm still not entirely sure of what you're trying to achieve exactly so I'm gonna assume the following:
You have a tab bar controller with 5 items. Each item is a navigation controller that has a specific class. Based on the url parameter passed to application:openURL:sourceApplication:annotation: you want to select the proper item (which was already been loaded previously in application: didFinishLaunchingWithOptions) of your tab bar controller .
Here's my attempt:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
if ([scheme hasPrefix:#"xyz"]) {
Class navigationControllerClass = [SearchTableViewController class];
NSUInteger navigationControllerIndex = [self.tabBarController.viewControllers indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
BOOL found = [obj isKindOfClass:navigationControllerClass];
if (found) {
*stop = YES;
}
return found;
}];
if (NSNotFound != navigationControllerIndex) {
self.tabBarController.selectedIndex = navigationControllerIndex;
}
}
}
Take 2
In your 2 attempts you're creating a new navigation controller and then try to push it on something that's nil (self.tabBarController.selectedViewController.navigationController is nil since self.tabBarController.selectedViewController is a navigation controller).
Whatever you're pushing in your navigation controller cannot be another navigation controller. So you need to create a simple view controller of type UIViewController and push it to the currently selected navigation controller of your tab bar.
if ([scheme hasPrefix:#"xyz"]) {
MYViewController *controller = [[MYViewController alloc] initWithManagedObjectContext:inMemoryContext];
[(UINavigationController *)self.tabBarController.selectedViewController pushViewController:controller animated:YES];
}
I have a specific view opening when opening my app from a notification. The navigation bar shows up and the navigation works correctly. The problem I'm having is getting the tab bar to show up. Here is my didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// This prevents the UA Library from registering with UIApplcation by default when
// registerForRemoteNotifications is called. This will allow you to prompt your
// users at a later time. This gives your app the opportunity to explain the benefits
// of push or allows users to turn it on explicitly in a settings screen.
// If you just want everyone to immediately be prompted for push, you can
// leave this line out.
// [UAPush setDefaultPushEnabledValue:NO];
//Create Airship options dictionary and add the required UIApplication launchOptions
NSMutableDictionary *takeOffOptions = [NSMutableDictionary dictionary];
[takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
// Call takeOff (which creates the UAirship singleton), passing in the launch options so the
// library can properly record when the app is launched from a push notification. This call is
// required.
//
// Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
[UAirship takeOff:takeOffOptions];
// Set the icon badge to zero on startup (optional)
[[UAPush shared] resetBadge];
// Register for remote notfications with the UA Library. This call is required.
[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];
// Handle any incoming incoming push notifications.
// This will invoke `handleBackgroundNotification` on your UAPushNotificationDelegate.
[[UAPush shared] handleNotification:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]
applicationState:application.applicationState];
// self.tabBarController = [[UITabBarController alloc] initWithNibName:#"KFBViewController" bundle:nil];
KFBViewController *rootView = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
KFBNavControllerViewController *navController = [[KFBNavControllerViewController alloc] initWithRootViewController:rootView];
navController.delegate = rootView;
UIViewController *aboutUs = [[AboutUs alloc] initWithNibName:#"AboutUs" bundle:nil];
KFBNavControllerViewController *navController1 = [[KFBNavControllerViewController alloc] initWithRootViewController:aboutUs];
UIViewController *contactUs = [[ContactUs alloc] initWithNibName:#"ContactUs" bundle:nil];
KFBNavControllerViewController *navController2 = [[KFBNavControllerViewController alloc] initWithRootViewController:contactUs];
UIViewController *kyfb = [[KYFB alloc] initWithNibName:#"KYFB" bundle:nil];
KFBNavControllerViewController *navController3 = [[KFBNavControllerViewController alloc] initWithRootViewController:kyfb];
// UIViewController *rsfm = [[RSFM alloc] initWithNibName:#"RSFM" bundle:nil];
// KFBNavControllerViewController *navController4 = [[KFBNavControllerViewController alloc] initWithRootViewController:rsfm];
// UIViewController *li = [[LegislatorInfo alloc] initWithNibName:#"LegislatorInfo" bundle:nil];
// KFBNavControllerViewController *navController5 = [[KFBNavControllerViewController alloc] initWithRootViewController:li];
// UIViewController *events = [[Events alloc] initWithNibName:#"Events" bundle:nil];
// KFBNavControllerViewController *navController6 = [[KFBNavControllerViewController alloc] initWithRootViewController:events];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//self.viewController = [[KFBViewController alloc] initWithNibName:#"KFBViewController" bundle:nil];
//self.window.rootViewController = self.viewController;
self.tabBarController = [[KFBTabBarViewController alloc] init];
self.tabBarController.viewControllers = #[navController, navController1, navController2, navController3];
// self.tabBarController.customizableViewControllers = nil;
self.window.rootViewController = self.tabBarController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// If application is launched due to notification,present another view controller.
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification)
{
ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc] initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[actionAlerts setWebViewController:wvc];
KFBNavControllerViewController *navController7 = [[KFBNavControllerViewController alloc] initWithRootViewController:actionAlerts];
[self.window.rootViewController presentViewController:navController7 animated:NO completion:nil];
}
return YES;
}
I have a UISplitViewController that is set up like so:
-(IBAction)makeStory:(id)sender{
NSLog(#"makeStory:");
makeStoryTableViewController = [[MakeStoryTableViewController alloc] initWithNibName:#"MakeStoryTableViewController" bundle:nil];
MakeSentenceTableViewController *detailViewController = [[MakeSentenceTableViewController alloc] initWithNibName:#"MakeSentenceTableViewController" bundle:nil];
UISplitViewController *splitViewController = [[[UISplitViewController alloc] init] autorelease];
UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:makeStoryTableViewController]autorelease];
UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, detailNav, nil];
splitViewController.delegate = makeStoryTableViewController;
StoryBotAppDelegate *appDelegate = (StoryBotAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:splitViewController];
}
When I try to set detailView in the UISplitView delegate as a result of didSelectRowAtIndexPath:, I can only access the NavigationController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"ViewControllers: %#", [self.splitViewController viewControllers]);
MakeSentenceTableViewController *detailViewController = [[self.splitViewController viewControllers] objectAtIndex:1];
Story *storySet = [fetchedResultsController objectAtIndexPath:indexPath];
NSLog(#"detailViewController: %#", detailViewController); //Logs a UINavigationController
[detailViewController setStory:storySet]; //Fails here because Navigation Controllers Can't setStory!
[detailViewController refreshTables];
}
Which makes sense, but how do I access the TableViews that the UINavigationControllers are responsible for? If I remove *rootNav and *detailNav and replace them with the UITableViews in the splitViewController.viewControllers statement it works fine, but then I have no navigation bar:
MakeSentenceTableViewController *detailViewController = [[MakeSentenceTableViewController alloc] initWithNibName:#"MakeSentenceTableViewController" bundle:nil];
UISplitViewController *splitViewController = [[[UISplitViewController alloc] init] autorelease];
//UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:makeStoryTableViewController]autorelease];
//UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
splitViewController.viewControllers = [NSArray arrayWithObjects:makeStoryTableViewController, detailViewController, nil];
splitViewController.delegate = makeStoryTableViewController;
StoryBotAppDelegate *appDelegate = (StoryBotAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:splitViewController];
How can I access the Detail TableView Controller and keep the Navigation Bar?
Here's how I figured it out. I made two mistakes, and in those mistakes I had to use the UINavigationController.viewControllers ObjectAtIndex: property.
In the function makeStory I was incorrectly assigning a UINavigationController as a delegate instead of a makeStoryTableViewController. I fixed it by doing this, instead (pay special attention to the splitViewController.delegate section):
MakeSentenceTableViewController *detailViewController = [[MakeSentenceTableViewController alloc] initWithNibName:#"MakeSentenceTableViewController" bundle:nil];
UISplitViewController *splitViewController = [[[UISplitViewController alloc] init] autorelease];
UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:makeStoryTableViewController]autorelease];
UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, detailNav, nil];
//splitViewController.viewControllers = [NSArray arrayWithObjects:makeStoryTableViewController, detailViewController, nil];
//RootViewController *root = (RootViewController *)[navigationController.viewControllers objectAtIndex:0]
splitViewController.delegate = [rootNav.viewControllers objectAtIndex:0];
NSLog(#"delegate: %#", [rootNav.viewControllers objectAtIndex:0]);
StoryBotAppDelegate *appDelegate = (StoryBotAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(#"RootViewController: %#", appDelegate.window);
[appDelegate.window setRootViewController:splitViewController];
NSLog(#"AppDelegate.window: %#", appDelegate.window.rootViewController);
I made the same mistake again, this time in the didSelectRowAtIndexPath: and tried to setStory in a UINavigationController. To fix it, I did this (pay special attention to the bit about navControllerDetail.viewControllers:
UINavigationController *navControllerDetail;
navControllerDetail = [[self.splitViewController viewControllers] objectAtIndex:1];
MakeSentenceTableViewController *detailViewController;
detailViewController = [navControllerDetail.viewControllers objectAtIndex:0];
Story *storySet = [fetchedResultsController objectAtIndexPath:indexPath];
NSLog(#"detailViewController: %#", detailViewController);
[detailViewController setStory:storySet];
[detailViewController refreshTables];
Now if only I could figure out how to get the SplitViewController to rotate properly!