UITabBarController UIViewController View with TabBarCtrl doesn't appear in my ViewCtrl :( - iphone

I have MainController class for UITabBarController's view managing.
When I try to display my TabBarController from ViewController - it display clear screen. :-( I could display my TabBarController only from __AppDelegate. =)
How can I display TabBarController from my UIViewController based view? =)
Please help me guys. Thank you a lot. =)
// MainController.h
#interface MainController : UIViewController {
IBOutlet UITabBarController * tabBarController;
}
#property (nonatomic, retain) IBOutlet UITabBarController * tabBarController;
#end
I have MyTestAppDelegate:
// MyTestAppDelegate.h
#import "MainController.h"
#class MainController;
#interface MyTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainController * mController;
IBOutlet UIViewController * viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) MainController * mController;
#property (nonatomic, retain) IBOutlet UIViewController * viewController;
#end
// MyTestAppDelegate.m
#import "MyTestAppDelegate.h"
#implementation MyTestAppDelegate
#synthesize window, mController, viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
MainController * mc = [[MainController alloc] initWithNibName:#"MainView" bundle:nil];
self.mController = mc;
[mc release];
[window addSubview:[self.viewController view]];
[[viewController view] addSubview:[mController.tabBarController view]];
[window makeKeyAndVisible];
}
#end

Documentation says that UITabBarController has to be on root level. See links and possible workarounds here: http://discussions.apple.com/thread.jspa?threadID=2190703&tstart=0
I have posted full project with working code here, based on code on above thread: http://discussions.apple.com/thread.jspa?messageID=10708521&#10708521

Related

Issue in creating a tabbed navigation app in ios 5 with xcode 4

I am trying to change a tabbed application on xcode 4 to incorporate a navigation controller without storyboard.
The 1st tab contains a table. This is the one that needs to be navigable.
Here is FirstViewController.h
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *storeDetailsTable;
}
#property (nonatomic, retain) UITableView *storeDetailsTable;
#property (nonatomic, strong) NSDictionary *resultData;
#property (nonatomic, strong) NSMutableArray *populatedStoreArray;
#property (nonatomic, strong) NSMutableArray *images;
#end
Here's the NavController.h:
#import <UIKit/UIKit.h>
#interface NavController : UINavigationController
#property (nonatomic,retain) IBOutlet UINavigationController * navController;
#end
So, I'm using NavController as a UIViewControllerSubclass and then changed it to the above.
The AppDelegate.h:
#import <UIKit/UIKit.h>
#class NavController;
#interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> {
IBOutlet NavController *navController;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UITabBarController *tabBarController;
#property (strong, nonatomic) IBOutlet NavController *navController;
#end
And AppDelegate.m:
#import "AppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "NavController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize tabBarController = _tabBarController;
#synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
navController = [[NavController alloc] initWithNibName:#"NavController" bundle:nil];
// UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Now when I build and run it, I see 2 tabs. But the first tab is just a blank black screen depicting the Navigation controller but there's no tableview as should be.
Is there something I have missed?
Thanks..
In your code I can't see that you're initing the FirstViewController class and making it known to the NavController. The NavController needs to init with a RootViewController, like:
NavController *myNavController = [[NavController alloc] initWithRootViewController:yourFirstViewController];
A good place to find more info is at:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

how to show tabbar controller into next View

I have a TabBar Controller in AppDelegate and then Navigation Controller on TabBar. But i get problem when i push Navigation Controller to other View Controller while remaining on first tabItem of TabBar.
My AppDelegate.h is:
#interface IlmStreamAppDelegate : NSObject <UIApplicationDelegate,UINavigationControllerDelegate,UINavigationControllerDelegate>
{
UIWindow *window;
UITabBarController *rootViewController;
UINavigationController *_navController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *rootViewController;
#property (nonatomic, retain) UINavigationController *navController;
#end
My AppDelegate.m is:
#import "IlmStreamAppDelegate.h"
#implementation IlmStreamAppDelegate
#synthesize window;
#synthesize rootViewController;
#synthesize navController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[rootViewController setTitle:#"Categories"];
_navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[window addSubview:_navController.view];
[self.window makeKeyAndVisible];
return YES;
}
#end
You can write write a custom XXTabBarController (plain subclass of UIViewController) that can be pushed onto a nav controller stack, but still have all the functionality of "view controller. Each "tab" has its own view controller.

UINavigationController not showing up when running build

EDIT: Working, see code below.
Working on an application, where right now I have the AppDelegate class, and a custom UINavigationController class. The code i have right now is pretty simple, and I feel like I've setup the XIB correctly. The build succeeds with no errors. But when the app launches, the navigationcontroller isnt displayed. I do not see the nav bar nor the table view. All I see is a blank screen. Here's the bulk of my code:
//
// FTPPhotosAppDelegate.h
// FTPPhotos
//
// Created by Aaron McLeod on 11-05-30.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "RootViewController.h"
#interface FTPPhotosAppDelegate : NSObject <UIApplicationDelegate> {
UINavigationController *navigationController;
RootViewController *rootViewController;
}
#property (nonatomic, retain) UINavigationController *navigationController;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) RootViewController *rootViewController;
#end
//
// FTPPhotosAppDelegate.m
// FTPPhotos
//
// Created by Aaron McLeod on 11-05-30.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FTPPhotosAppDelegate.h"
#implementation FTPPhotosAppDelegate
#synthesize window=_window;
#synthesize navigationController, rootViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
navigationController = [[UINavigationController alloc] init];
rootViewController = [[RootViewController alloc] init];
[self.navigationController pushViewController:rootViewController animated:NO];
[self.window addSubview:[self.navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
#interface RootViewController : UITableViewController<UIImagePickerControllerDelegate> {
NSMutableArray *photos;
UIImagePickerController *picker;
UIBarButtonItem *addPhotoButton;
}
#property (nonatomic, retain) NSMutableArray *photos;
#property (nonatomic, retain) UIImagePickerController *picker;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *addPhotoButton;
- (void) loadPhotos;
- (IBAction) addPhoto;
- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
#end
#import "RootViewController.h"
#implementation RootViewController
#synthesize photos, picker, addPhotoButton;
- (void)viewDidLoad
{
self.photos = [[NSMutableArray alloc] initWithCapacity:50];
[self loadPhotos];
[super viewDidLoad];
}
Any ideas? Here's a screenshot of the XIB,
.
Let me know if you need more info.
Instead of a root View controller, make it a UINavigationController *navigationController.
then in the applicationDidFinishLaunching, say
navigationController = [[UINavigationController alloc]init];
FirstViewController *firstView = [FirstViewController alloc]init];
[self pushViewController:firstView animated:NO];
firstView.title = #"TITLE";
[self addSubview:navigationController.view];
EDIT: some example code i have in an app of mine
AppDelegate.h
#import <UIKit/UIKit.h>
#interface DragonAge2AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TitleClass *titlePage = [[TitleClass alloc]init];
navigationController = [[UINavigationController alloc]init];
titlePage.title = #"Dragon Age 2";
[navigationController pushViewController:titlePage animated:NO];
[titlePage release];
// Override point for customization after application launch.
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
You need to check some points:
Is the code in application:didFinishLaunchingWithOptions: executed when you run the application? Add a NSLog(#"app launched") in this code or set a breakpoint in it to check it. If it is not called, your FTPPhotosAppDelegate object is probably not set as the delegate of your UIApplication singleton in the XIB (this connection should be done by default if you created your app using a standard template, but it's worth checking)
Is the navigationController IBOutlet of your AppDelegate properly connected to your actual UINavigationController in the XIB? Check (using an NSLog or a breakpoint) that it is not nil.
Same for the view IBOutlet of the UINavigationController object in your XIB: check that it is properly connected and not nil.

problem in UINavigation controller

hi to all
i am trying to do a simple navigation based application.this is my code
#import <UIKit/UIKit.h>
#class RootViewController;
#interface jeeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
RootViewController *viewcontroller;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#property (nonatomic, retain) IBOutlet RootViewController *viewcontroller;
#end
.m file
#import "jeeAppDelegate.h"
#import "RootViewController.h"
#implementation jeeAppDelegate
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
For this code i got "Application tried to push a nil view controller on target <UINavigationController: 0x4b4f5c0>." thanks in advance..
This is fairly simple - at no point have you initialised the view controller that you're attempting to push onto the navigation stack.
i.e.: Before you call..
navigationController=[[UINavigationController alloc]initWithRootViewController:viewcontroller];
...you need to ensure that viewcontroller actually exists, in the sense that you need to alloc and init it.
For example:
// Create our main menu view controller
MainMenuViewController *mainMenuVC = [[MainMenuViewController alloc] init];
// Create our navigational controller and init it with the main menu view controller
navController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];
[mainMenuVC release];
In the above mainMenuVC is a custom view controller that I've created.
Also, please note that once you've added your view controller to the navigation controller, you can release it as the navigation controller with retain it.

iPhone navigationController is not displayed

I have a very strange behaviour of my navigation view. What I want is, that from my main view, the user can touch a button, which leads him to the view with the application settings.
Here is the code, responsible for the navigation:
AppDelegate.h
#interface AppDelegate : NSObject {
UIWindow *window;
ViewController *viewController; // My Main View Controller
UINavigationController *navigationController; }
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ViewController *viewController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
AppDelegate.m
#synthesize viewController;
#synthesize window;
#synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:viewController.view];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
viewController.h
#import
#import "optionsViewController.h" // the 'settings' view controller
#class AppDelegate;
#interface ViewController : UIViewController {
AppDelegate *appDelegate;
viewController.m
- (IBAction)showOptionsViewController:(UIBarButtonItem *)sender {
// optionsController.theSubjectID = self.theSubjectID;
// [self presentModalViewController:self.optionsController animated:YES];
optionsViewController *optionsController= [[optionsViewController alloc] initWithNibName:#"optionsViewController" bundle:nil];
optionsController.theSubjectID = self.theSubjectID;
[self.navigationController pushViewController:optionsController animated:YES];
[optionsController release];
}
My optionsController is a 'normal' UIViewController. As you see did I change the load of the optionsController from modal to navigation. Could it be, that I missed something here?
Thanks for any hints in advance.
Cheers, René
Have you connected it up in Interface Builder if not you need to alloc/init it before you add it as a subview?