Strange behavior with MainWindow.xib, app will not reach didFinishLaunchingWithOptions - iphone

I've started a new project in Xcode 3.2.5 where everything is being done in code. I don't want to use xibs this time though am looking forward to an integrated IB in Xcode 4.
The problem came up when I edited a string in a json file. On running the code I noticed the old string appearing even though the file was certainly changed, so I deleted my Library/Application Support/iPhone Simulator folder, expecting that my json changes would then be loaded to the bundle and the code would then see the expected value.
Then command-Y to build and run and it wouldn't run. Although there is no MainWindow.xib in my project folder my Info.plist file refers to MainWindow.xib. (I removed it, following the creation of this iPhone app with Xcode's New Project template) So I removed that key from the plist figuring the xib must have been sitting around in the app bundle after being installed in the simulator the first time I ran the app.
Then I ran the app again. No complaints, only a black screen - and a breakpoint in my app delegate, on didFinishLaunchingWithOptions is not being hit.
I have not changed anything in main.m. How can it be that the app is not launching?

I think something got messed up when you removed MainWindow.xib. Try these steps to see if it'll correct the problem.
Under the Project menu, choose Edit Active Target. Select the Properties tab and blank out the Main Nib File field. Close the Target Info window.
Under the Other Sources group and edit the main.m file. In the UIApplicationMain function call, change the last parameter to the name of your application delegate class.
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
In your application delegate you need to create a window object. I do this in -applicationDidFinishLaunching:. If you defined anything else in your MainWindow.xib, you can probably create that here, too.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIWindow *appWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = appWindow;
[appWindow release];
}
If this doesn't work, let me know and I can give you another way.

Sounds like you dont have a view connected in the XIB.

This is the same as #"AppDelegate" but you can write like this too :
(argc, argv, nil, NSStringFromClass([AppDelegate class]))

Related

Could not load NIB in bundle - inspiration needed

I'm currently seeing this error:
MonoTouchException: Objective-C exception thrown. Name:
NSInternalInconsistencyException Reason: Could not load NIB in bundle:
'NSBundle </Users/imac/Library/Application Support/iPhone
Simulator/5.0/Applications/5D8B4B51-9FB2-4331-BFEB-B1A0AC77DF42/Tutorial.app>
(loaded)' with name 'MyFirstView'
I've looked through lots of other questions like:
NSInternalInconsistencyException Could not load nib in bundle
Could not load NIB in bundle
and lots of others
But I can't see that any apply here - they are mainly about file naming issues and my Nib does appear to be in the output package file with the correct name.
I'm using MonoTouch 5.2.5 and xcode 4.2, and targeting SDK5
Does anyone have any ideas about what I could try to fix this?
I have faced the same Problem today. I refactored (rename) viewController to myCustomViewController and got this error. When I searched in my project files, I saw that I have used self.viewController = [[[MyTableViewController alloc] initWithNibName:#"viewController" bundle:nil] autorelease];
NibName was changed but in #" " it was old name. so I changed it to
self.viewController = [[[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil] autorelease];
and error was removed. Do it and hope your error will be removed.
Vote up if it helps.
The problem eventually it seems was somewhere in the extended toolchain - somewhere between MonoDevelop, xCode4 and the simulator.
Restarting everything, and resetting the simulator cleared the problem.
Later in the same chain I've seen smaller issues with "old NIB file outlets" persisting on the simulator even after I've definitely deleted them and rebuilt - so something is still going wrong somewhere... but a clean solves it each time.
So I had a similar solution in MonoDevelop. I created an empty mono touch project. When I deleted the xib file associated with the auto created project, i ran into problems. Even though I created a new view and connected the outlet to that controller, I had to go back and recreate the xib file associated with the controller (with the same name) again, and then connect that original view and controller via the outlet

How does Xcode decide which xib to load first? How can I change that?

I have downloaded an Xcode project that has three xibs (A.xib, B.xib, and C.xib). I noticed that:
None of them is called "MainWindow.xib".
In the project summary the Main Interface value is set to MainWindow
Main nib file base name is not set
Main.c does not specify the app delegate either int retVal = UIApplicationMain(argc, argv, nil, nil);
Still, when I build&run, the app loads A.xib.
How does the app decide what to load?
I am using Xcode 4 and I am targeting iOS 5.
Thank you.
You can set the Main Interface in the Summary tab of your app target.
See this image:
EDIT: Or, as Alan wrote, you can set it in your info.plist file.
EDIT 2: Oh. I see what your problem is. You can use MainWindow as your main .xib file, but you have to edit which .xib is loaded in MainWindow. Open MainWindow.xib, and select the view controller that is used. If I'm right, its class is set to A. If you want B.xib to be used, you have to change the class to B. You will also have to set the NIB being used for the view controller, in the Attribute Inspector.
Set the class for the UIViewController being used in MainWindow.xib:
Set the NIB:
In your application's Info.plist.

Do I really need a MainWindow.xib file?

I have an iPad 4.3 project that doesn't have a MainWindow.xib because it's main view is created programmatically. Everything seems to work fine but I noticed that in my plist file there's a value for a NSMainNibFile key that has "MainWindow" for value. If I change in any way that entry, my app won't work. Now, that's strange, at least for me...
If you remove the xib reference in the target properties, be sure to change your code in main.m to refer to your class delegate class.
int retVal = UIApplicationMain(argc, argv, nil, #"YourAppDelegateClassName");
If you remove the NSMainNibFile key from your Info.plist, you need to update the code for main.m. You will need to update the NSString *delegateClassName in the call to UIApplicationMain.
No you don't necessarily need something called MainWindow.xib you could rename everywhere but as this answer points out you have to have something for the application to start with; What's the MainWindow.xib nib file for?

Xcode 4: nib files not loading when run

So, I just downloaded Xcode 4 and installed it. I was actually quite looking forward to the single window and integrated IB...
-
However, when I open and run one of my projects, the nib files that the project uses don't seem to load. Instead I'm left looking at a blank white screen (iPhone). This project ran well and fine on Xcode 3.2.
If I background and un-background the app, the view loads fine. But this happens every time I build, on both iPhone and iOS simulator, i.e. the app doesn't work properly until it's been backgrounded. All the code for loading the view follows from
- (void)applicationDidFinishLaunching:(UIApplication *)application.
-
Did anyone else have the same nib file problems - is there a fix (or something stupidly simple that I'm forgetting about)?
Ok after a lot of messing around, I figured out the nib problem.
I had a stray line of code in the appDelegate class:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
This line of code doesn't affect anything when compiling with Xcode 3.2, but with Xcode 4 causes the loading problem. Just remove it (I don't even remember why it was there...) and it's fixed :)
I'm not sure what's going on with your nibs, but this XCode 4 transition guide should be of some help for finding missing panels, menus etc...
I had the same problem. In my case, for some reason Xcode had decided to hide the view in question. It cleared up when I put the following into the viewDidAppear method of the view controller:
self.view.hidden = NO;
For anyone with the same error. If upper won't help - check if you did not overwrite the view attribute of your ViewController.

XCode error: "GDB:Program received signal: "SIGABRT"."

I am writing a simple application using cocos2d 0.99.5, the iPhone SDK is 4.2. I have run my application on device, but when I press the button to switch CCScenes, sometimes the app suddenly has no response and XCode received the error:"GDB:Program received signal:"SIGABRT". "
This issue happens by accident. You have to press the transition button many times to reproduce this bug.
I have learned that SIGABRT is raised by the abort() function. abort() is called by the standard assert() macro when an assertion fails. But there is no assert function in my program.
Could anyone tell me how does this problem happen, and how to solve this problem? I don't know what to do next now.
The problem has been solved. See the comments above.
If you get SIGABRT when app starts check your XIBS
Open each XIB
Check the Files Owner in each in the Identity Inspector
Make sure the class mentioned is the correct one and class exists (I had renamed some files and it failed)
Start with
MainWindow.xib
RootViewController.xib
Check Class names in Identity Inspector is ok.
Place breakpoints in
AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//if it enters this method then MainWindow.xib ok
STEP 2 - in didFinishLaunchingWithOptions place another breakpoint on
self.window.rootViewController = self.viewController;
In the RootViewController.m (or whatever sub class of VC self.viewController in AppDelegate is) place a break point in
viewDidLoad
If it crashes here check RootViewController.xib (or what ever class the first VC is)
and check Class is correct for Files Owner
iterate down through all View controllers
look for initWithNibName to find what XIBs are called.
In each check the Class name in the XIb is set correctly.