What are some reasons that application:didFinishLaunchingWithOptions method could get skipped? - iphone-sdk-3.0

My iPad app was working fine until I opened up IB and started editing the interface. Now, my application:didFinishLaunchingWithOptions isn't getting called. I understand it's an optional function and it gets skipped if it doesn't exist, but in my case it does. What are some reasons that application:didFinishLaunchingWithOptions method could get skipped?
I should note that I'm building with the iPhone OS 3.2 SDK.
Thanks in advance for your help!
UPDATE: I fixed it, please see my answer below

Are you sure that class has been set as the application delegate of the app?
(source: xanga.com)
And also make sure the "File's Owner"'s delegate has been linked to "App Delegate".
(source: xanga.com)

Well it turns out, for an unknown reason, I had a "view" view object as a child of my RootViewController in IB that didn't serve any purpose except to hold my a TableView view object and a DatePicker view object. I thought it was harmless, but when I removed it in IB and programmatically added the TableView object and and DatePicker object, suddenly this problem went away. If anyone has any ideas why this is, I'd would love to understand it.
Thanks, everyone!

Related

Error loading .xib - application crash

I am banging my head against a brick wall. I am trying to push a view onto a UINavigationController in the usual manner:
[[self navigationController]pushViewController:vc animated:YES];
When I do this the app crashes with the following error:
__CFStringEncodeByteStream + 17
Thread 1: EXC_BAD_ACCESS (code=2,address=xxxxx)
Now, I have replaced the ViewController in question with a template provided by XCode and I do not get the error so the issue must be with my UIViewController class. Furthermore, if I replace the nib name with that of the template UIViewController class it works .i.e.
MyViewController *myVc = [[MyViewController alloc]initWithNibName:#"XCodeViewController" bundle:nil];
This leads me to think that the issue is actually with the nib and not the class itself. I have checked through all the connections and there are no errors or warnings.
Hopefully somebody can help.
Thanks
I was dealing with a very frustrating bug similar to yours, and everything was in place.
The newly created xib was added to the Bundle resources, no nil pointers or released pointer, NSZombieEnabled was set. The File's Owner was set to the correct ViewController as well
After sitting down with my senior for 30 minutes, we finally realized what was wrong -
In the newly created Xib, even after you assign the File's Owner to the ViewController there is an additional step which you need to take.
You need to have the main View's referencing Outlet set to the File's owner as well. The easiest way to do this is to Drag the "+" sign on the referencing outlet(From the Connections inspector) to the "File's Owner" in the Document Outline. After this you just need to click on "view" which pops up and you should be good.
Hope that helps you or anyone else facing the same problem
Need more info to answer, I can give few possibilities.
Check if the class name is mapped properly in your identity inspector.
And check your connections too. If your view is mapped in xib., etc.
If your running the app in OS below 6.0 & built with features such as Auto layout, it leads to crash.
There are multiple possibilities.
Hope this gives an insight.
Check if your nib is added to the application bundle. You can do that by selection you project file->Build Phases->Copy Bundle Resources.
If it is not there, add it.
I had the same issue yesterday and this was the problem.
I hope it helps.

Connecting App Delegate to Controller Class

I'm stuck on this step of developing an XCode application: https://developer.apple.com/library/mac/#documentation/General/Conceptual/Mac101/Articles/07_WhereNext.html
What I'm confused about is the role of the AppDelegate class that's created by default when creating a project initially in XCode 4. If I implement a custom controller, let's use the example link above and call it TrackController. Do I make that controller the app delegate? It seems any tutorial I read isn't very clear on this.
So, in AppDelegate, do I create a new instance of the controller class here? And if so, do I then hook up the outlet here? Or do I change the File's Owner to be the controller class? If that's the case, then how's that done in XCode 4?
Not a very well defined question I know, but I'm sure someone knows what I'm talking about.
EDIT
The following screenshot shows what I mean. The blue box is now "Track Controller". I've shown the AppDelegate class in this case though to make it clear. What do I use, AppDelegate.m, or TrackController.m? How should it be done?
EDIT 2
Going back to this, I've uploaded the code to GitHub here as I still haven't figured out how to hook everything up.
To re-explain, I need to figure out how AppDelegate and TrackController all relate and communicate with one another. The concepts are generally new to me and I've read the Apple documentation but they haven't really helped me. I've even had in-depth discussions with experts and I still fail to see how it should work.
My model is Track, then I have TrackController and of course AppDelegate. AppDelegate is instantiating TrackController and I was hoping that it'd be able to open up its window.
What am I doing wrong? Hopefully an expert can help me!
What it's describing is that the application delegate should focus on handling the delegate calls sent to the app.
You actually create a new class to act as the primary controller of the app, and then you add code to call it when the app is finished loading. From there on out, that app is (supposedly) your primary control point (except, of course, when it 'hands off' to another class).
I'm more familiar with how the process works on iOS than Macs, which have to worry about windows, but for an iOS app you'd add code to call your starting view controller from inside ApplicationDidFinishLaunching:WithOptions:. From there, the view controller takes off, and the easiest way to view the entire process is that you start at the view controller (that's how most tutorials handle it, in fact, letting XCode handle the fact that the app delegate creates that view controller).

How do I use a RootViewController when making an app without a ViewController?

I am trying to make a simple app from a tutorial that does not have a viewController at all. All the code is in the AppDelegate. I am on xcode 4.2 and I am getting this error:
Applications are expected to have a root view controller at the end of application launch
I'm not sure how to deal with this. There are some blogs out there with fixes but none of them are working for me and I really would like to understand what is going on here. And, how to fix it.
I do have a view that contains some buttons and labels. But I have no "ViewController". The files contained in my project are: AppDelegate.h, AppDelegate.m, and Window.xib only. There is no ViewController.h, ViewController.m
** edit **
I ended up making the app from a 'view based application' instead and just moving all the logic from the app delegate to the view controller. So, I didn't really solve the problem per se. The app works now though. Thanks for the help
It's not possible to have an iOS app that doesn't have a view controller. You can always create a trivial view controller, i.e.,
[[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds].rootViewController =
[[[UIViewController alloc] init] autorelease];
It sounds like you're looking at an old tutorial. UIWindow got a rooViewController property in iOS4. I believe it became required in iOS5 to help keep controller hierarchies and view hierarchies in sync with the addition of custom container controllers (and to fix a corner case where replacing the "root controller" of a UIWindow could stop orientation changes from propagating). There was a WWDC presentation in 2011 that explained this in some detail. I think it was Session 102, Implementing UIViewController Containment.
At then end of the day, there's no good reason not to have a root view controller. Apple wants to be able to assume it's there in their APIs going forward. If the tutorial you're looking at doesn't account for that, it's broken.
While I agree that there may be workarounds, another question to address is: why do you want an app without a view? Even if it's designed to run in the background and present no visual interface, at least make a simple view showing the application name and version, a largeish icon and perhaps a status. This kind of idle screen uses very little system resources, especially when the app is backgrounded, but improves the overall experience of the app.
If you set your deployment target to 4.3 and run on the iPhone 4.3 simulator, you won't get the warning.
To install the iOS 4.3 simulator, go to Xcode > Preferences > Downloads.

Compiler Error in a Blank Project

I've started a new Navigation-based project in X-Code. I delete the default grid view, add a new blank view, and connect it to the File's Owner via ctrl+click+drag, and it builds fine, but before anything happens on the iPhone simulator or the real thing, I get "Thread 1: Program recieved signal: "SIGABRT"" when the program hits "[self.window makeKeyAndVisible]". I'm really new to Objective-C and X-Code, but I know quite a bit of C# and C++. I don't really understand if I've set something in the IDE wrong, or what...any help would be greatly appreciated. Thanks!
When you create a new navigation project, the RootViewController class is a subclass of UITableViewController. Your error is due to removing the UITableView from the xib file, and replacing it with a UIView.
To fix this, you should change the super class of RootViewController to UIViewController. (Don't forget to remove the UITableView datasource and delegate methods from the implementation file for clarity.)

iOS 3 - UITabBarItems disappear from UITabBar after a memory warning occurs

At a great number of requests from people using older iOS hardware, I'm currently refactoring and optimizing my app so it will work on iOS 3. That being said I've got a glitch with my UITabBar that I can replicate on all of the iPhone 3G units I've tested it on.
The glitch appears to have been fixed in iOS 4, but I was wondering if before that time, anyone else had this glitch as well and had figured out a (relatively elegant) workaround for it.
The problem is what you can see below; when a memory warning occurs and all of the views offscreen are released, when I bring a view controller with a tab bar back on screen, all of the UITabBarItems that are supposed to be in it are gone. As far as I can see, they're not being drawn at all; ie tapping the tab bar has no effect. After setting breakpoints and examining the UITabBar and its items in memory, they're all still there (ie not getting released), just that they're not getting redrawn when the UITabBar is re-created in the controller loadView method.
My app works similar to the official Twitter app in that I implemented my own version of UITabBarController so I could control the integration of it with a parent UINavigationController properly. I set it up as closely as possible to the original UITabBarController class though, with all of the child view controllers handling their own respective UITabBarItems and initializing them inside the class' init methods. Once the child view controllers are passed to my TabController object via an accessor method, the tabBarItems are accessed and added to the UITabBar view.
Has anyone seen this behaviour before and know of a way I can fix it? I'm hoping there's a really simple fix for this since it already works in iOS 4, so I don't want to hack it up too badly.
Thanks a lot!
After a bit of research, I think I found a solution to this. It's not the most elegant solution I was after, but it definitely works.
I'm guessing after a memory warning is triggered, something is happening to the UITabBarItem objects that basically renders them corrupt. I tried a lot of things (flushing out the UITabBar, re-creating the controllers array etc), but nothing worked.
I finally discovered that if you completely destroy the UITabBarItems and allocate new ones in their place, then those ones will work. :)
So my final solution to this was to add an extra condition in the viewDidLoad method of my controller that if the detected system was iOS 3, and there was already an array of UITabBarItems, it would go through each one, copy out all of the properties needed, destroy it, allocate a new one and then copy the old properties over to the new one.
I'm still going to keep an eye out for a better solution (I think there's a bit of overhead in this method), but thankfully at this stage, iOS 3 legacy support is becoming less and less of an issue. :)