How to properly add a Navigation Controller to my Search View with hidden Navigation Bar - iphone

When my app is launched the first screen (view) the user sees when my app is launched is a search form without any navigation. Navigation will show up after search process is done and results are ready to be displayed. Where I'm stuck at is the proper way to make it work with the navigation controller.
So, assuming the app name is RealEsateProperties
In RealEsatePropertiesAppDelegate.h:
#import <UIKit/UIKit.h>
#class RealEsatePropertiesViewController;
#interface RealEsatePropertiesAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *ListingNav;
}
#property (nonatomic, retain) IBOutlet UIWindow window;
#property (nonatomic, retain) RealEsatePropertiesViewController *viewController;
// Then I added this line for the navigation
#property (nonatomic, retain) UINavigationController *ListingNav;
#end
and in RealEsatePropertiesAppDelegate.m:
#import "RealEsatePropertiesAppDelegate.h"
#import "RealEsatePropertiesViewController.h"
#synthesize window=_window;
#synthesize window=_viewController;
#synthesize ListingNav;
#implementation RealEsatePropertiesAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLanchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.viewController;
// Iadded the following 4 lines to try making the navigation thing work without showing any navigation bar on the first screen (that is the search form)
self.ListingNav = [[UINavigationController alloc] initWithRootController:self.viewController];
self.ListingNav.navigationBarHidden = YES;
[self.window addSubView:ListingNav.view];
[self.window makeKeyAndVisible];
return YES;
}
#end
Am I doing anything wrong ?
Thx for helping,
Stephane

You need to create/alloc your RealEsatePropertiesViewController ?
viewController = [[RealEsatePropertiesViewController alloc] init];

Related

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.

iPhone Loading Different Views

I have to xibs, and I want to load which one the user wants in the settings. I'm just working on actually loading them and how would this been done.
This is the function in the delegate which I think would be where this happens.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
This is the delegate header file.
#import <UIKit/UIKit.h>
#class myAppViewController;
#interface myAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
myAppViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet myAppViewController *viewController;
#end
So lets say I have a xib created called modernTheme, how would I load that or the myAppViewController. If someone could do this in a generic if statement, that would be great.
This looks like your viewController is being created 'in Interface Builder'. Instead of that you could create the ViewControllers yourself and add them dynamically. Your application:didFinishLaunchingWithOptions: could look something like this:
UIViewController *viewController;
if (showModernTheme) { // from your configuration
viewController = [[YourViewControllerA alloc] initWith…];
} else {
viewController = [[YourViewControllerB alloc] initWith…];
}
// assuming YourViewControllerA + B are inheriting from UIViewController
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
Hope that helps
–f

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?

EXC_BAD_ACCESS in tableview application

This is my first iPhone application and it's based on a top-level tableview. Selections of rows either go to another tableview or to a view. The application runs OK on the simulator but when ported to my iPhone it fails with a EXC_BAD_ACCESS error. This happens while my splash screen is being displayed. NSLog indicates that the program processes in appDelegate.m:
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
but then it just fails. The code never seems to reach the viewDidLoad in my RootViewController.
I'm sure that I've got the RootViewController and appDelegates mixed up somehow but cannot figure out exactly what's wrong. I've attached the beginning code of my RootViewController, appDelegate - any help appreciated.
RootViewController.h code....
#interface RootViewController : UITableViewController {
TyresViewController *tyresController;
EngineSpecViewController *engineSpecController;
CarbonTaxBandViewController *carbonTaxBandController;
TyreSpecificationsViewController *tyreSpecificationsController;
FuelConsumptionandEmissionsViewController *fuelConsumptionandEmissionsController;
CompanyCarTaxBandViewController *companyCarTaxBandController;
CarbonCalculatorViewController *carbonCalculatorController;
ReminderViewController *reminderController;
//NSString *selectedSpecification;
NSArray *listOfItems;
}
RootViewController.m code ......
#import "RootViewController.h"
#implementation RootViewController
#synthesize listOfItems;
//#synthesize selectedSpecification;
#synthesize carbonTaxBandController;
#synthesize engineSpecController;
#synthesize tyreSpecificationsController;
#synthesize tyresController;
#synthesize fuelConsumptionandEmissionsController;
#synthesize companyCarTaxBandController;
#synthesize carbonCalculatorController;
#synthesize reminderController;
appDelegate.h code.....
#interface MyCar3AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
appDelegate.m code .....
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
Just a thought, in your main Info.plist file there should be an entry for Main nib file base name. This refers to the nib that will be loaded when your app starts. The simulator is not case sensitive, but the device is. Check the case of the value of your main nib.