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.
Related
I am starting an iPhone application, and I can't seem to get the main screen started. Here is my delegate.h file:
#import <UIKit/UIKit.h>
#class MainViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (retain, nonatomic) MainViewController *mainViewController;
#end
and here is my implementation file(at least the beginning):
#import "AppDelegate.h"
#import "MainViewController.h"
#implementation AppDelegate
#synthesize window = _window;
#synthesize mainViewController = _mainViewController;
- (void)dealloc
{
[_window release];
[_mainViewController];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController *aViewController = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
[self setMainViewController:aViewController];
[aViewController release];
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
When I try to run the app, just a black screen appears, and even after waiting a long time, the screen won't show the contents of my MainViewController.xib file...
Any ideas?
Main XIB of your application is MainWindow.xib. (It can be selected in project settings).
It contains app delegate, window and mainViewController (BTW, it should be better connected from XIB, not created manually in application:didFinishLaunching) connected to app delegate.
Check the connections.
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];
When my app first starts, it shows a main page to log in to Facebook. Then, it goes to the UITabBarController. The code that I have in my app delegate is the following:
//this is the .h
#interface NMeAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *controller;
UITabBarController *tabBar;
}
#property (nonatomic, retain) IBOutlet UITabBarController *tabBar;
#property (nonatomic, retain) MainViewController *controller;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
//this is the .m of the app delegate
#import "NMeAppDelegate.h"
#implementation NMeAppDelegate
#synthesize window;
#synthesize tabBar;
#synthesize controller;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
controller = [[MainViewController alloc] init];
[window addSubview:tabBar.view];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
Inside of MainViewController, I actually have a UserInfo object, which has all of the information that I need for the UITabBarController. The problem is that after getting this info in the UITabViewController, how do I pass this UserInfo to the UITabBarController` or possible the ViewController that is inside the UITabBarController so they were able to access this UserInfo? How to do this?
I hope my question makes sense.
you need to have an instance of your UserInfo object available to the tab bar controller. probably pass it into a instance variable of type UserInfo in your UItabBarController/each view controller whenever you transition into the specified controller.
edit: you should really have this passed into the view Controller it needs to be in (since it doesn't appear you have a custom UITabBarController subclass), or you could use a shared UserInfo variable in your app delegate to keep up with the information.
But as the commenter said, the question is not very clear at all and i could be completely misunderstanding what you want to do.
Hope that helps.
I have the following code in my AppDelegate.h file:
#class mainViewController;
#class AboutViewController;
#interface iSearchAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
mainViewController *viewController;
AboutViewController *aboutController;
UINavigationController *nav;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet mainViewController *viewController;
#property (nonatomic, retain) IBOutlet AboutViewController *aboutController;
#property (nonatomic, retain) IBOutlet UINavigationController *nav;
[...IBActions declared here...]
#end
Then, in my .m file:
#implementation iSearchAppDelegate
#synthesize window;
#synthesize viewController, aboutController, settingsData, nav, engines;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:nav.view];
[window addSubview:aboutController.view];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
-(IBAction)switchToHome{
[window bringSubviewToFront:viewController.view];
}
-(IBAction)switchToSettings{
[window bringSubviewToFront:nav.view];
}
-(IBAction)switchToAbout{
[window bringSubviewToFront:aboutController.view];
}
- (void)dealloc {
[viewController release];
[aboutController release];
[nav release];
[window release];
[super dealloc];
}
#end
Somehow, when I run the app, the main view presents itself fine... however, when I try to execute the actions to switch views, the app crashes with an EXC_BAD_ACCESS.
So, I think it has something to do with memory management, but I'm not quite sure.
Thanks for any help in advance.
Link to screenshots of code is here: link...
SOLVED: I fixed the issue by taking out the IBActions and making them into regular methods... apparently, XCode doesn't like it when you put IBActions in an AppDelegate.
... message sent to deallocated instance ...
If it is memory management, my first step would be to enable NSZombie and discover what was being messaged after being dealloc'ed. Two obvious things I can think of:
Uninitialised property/variable.
De-allocated (non-retained) property
Have your controls in interface builder been connected to the IBActions?
Somewhere in your code, you are invoking [iSearchAppDelegate performSelector:withObject:withObject:]. You haven't shown that code here but that's likely where the problem is.
When you create an application from the "View-Based" template in the iPhoneSDK the following code is generated. I basically understand what is happening here, but I do not see where window and viewController are instantiated. Any Help?
#class jojojViewController;
#interface jojojAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
jojojViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet jojojViewController *viewController;
#end
===============================================
#implementation Test6AppDelegate
#synthesize window,mainView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
#end
They come from the MainWindow.xib (or similar) file in your project.
This is the file that in your info.plist is set as the application window. When your application starts this xib is loaded and the viewcontroller and window are unarchived and loaded.
If you look in MainWindow.xib, the window and viewcontroller are assigned to your AppDelegate's window and viewController outlets, which instantiates them when the nib is loaded (right click on the AppDelegate to see it).