Without Windows Based Application


#1

How should this project be started without using Windows Based Application?

Thanks.


#2

I too am having this issue. I upgraded to XCode 4.2. Oops?


#3

Going to have to upgrade eventually and well before a 3rd edition.

Without a simple workaround I’ll be returning the book as I already have the first edition.


#4

Yes, it’s not meant for the beta. And Apple really decided to screw this one up.

  1. Open main.m. Find the function UIApplicationMain(), and make the last argument nil.

  2. Open QuizAppDelegate.h, put an IBOutlet in front of the window property.

  3. You can create a new Window XIB from the templates, name it MainWindow.

  4. Make the File’s Owner Identity a UIApplication (by selecting it, opening the utilities area, selecting the Identity inspector, and changing the Custom Class field).

  5. Add a NSObject to the XIB Object’s list, change the custom class of this object to QuizAppDelegate (the same way you did for the File’s Owner).

  6. Connect the window outlet of the QuizAppDelegate to the window object.

  7. Connect the delegate outlet of the File’s Owner to the QuizAppDelegate.

  8. Select the project. Select the Quiz target. Enter MainWindow into the Main Interface field.

  9. Now, select the Quiz project. Then select build settings. Search for “Automatic reference” and set both settings to “No”.

  10. And finally, remove the line from QuizAppDelegate.m that looks like this:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Then you are good to go.


#5

Awesome, thanks! I’ll give that a shot.


#6

Sorry for the trouble…still seem to be at a loss…

  1. Didn’t find @“QuizAppDelegate” in main.m but I change the following, is that correct?
    retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([QuizAppDelegate class]));

to

retVal = UIApplicationMain(argc, argv, nil, nil);

  1. No problems here. Should this have retain as in the book? Its default is (strong, nonatomic)

  2. No problem here

  3. Changed the Custom Class for the File’s Owner to UIApplication

  4. Added the NSObject to the XIB Object’s list and changed the label to QuizAppDelegate (Also tried Quiz App Delegate). Right clicking on the QuizAppDelegate object brings up a window with:

Referencing Outlets
New Referencing Outlet

Referencing Outlet Collections
New Referencing Outlet Collections

I declared the variables and methods in QuizAppDelegate.h, they should have appeared in the QuizAppDelegate object, correct?

  1. Should this be connecting the File’s Owner delegate to the window object?

  2. Added MainWindow to the Main Interface field.

Any help would be great. Thanks


#7
  1. Yes, that is correct, my fault, was going off memory.

  2. It should be retain, but you will also have to change your project to not use automatic reference counting. In fact, you will have to change all of your projects not to use automatic reference counting. (The book was already finished before automatic referencing counting was unveiled.) You can do this by selecting the project from the project navigator, choosing the project in the editor area, and choosing Build Settings. Then, find “Objective-C Automatic Reference Counting” option and set it to No.

  3. You’ll have to change it to QuizAppDelegate in the Identity inspector just like you did for the File’s Owner.

  4. Nope, once you change the Custom Class of the NSObject to QuizAppDelegate, that outlet will appear.

However, I did forget one step (apologies): connect the delegate outlet of the File’s Owner to the QuizAppDelegate.

Also, keep in mind we didn’t have a chance to see 4.2 before the book was written. There were a number of new feature added and the templates were changed again, so you’ll run into similar issues throughout the book. Such is the life of keeping up with Apple.


#8

Thanks alot Joe, everything made sense and built properly (yay!).

One strange problem…all connections appear to be correct, but neither of the IBAction methods get called. I added debug messages to the init, showQuestion, and showAnswer. init debug message displays in the log window, but the actions do not.

Is it possible Apple changed IBAction?

Jaime


#9

Figured out the problem. One of the auto-generated methods was preventing the actions from functioning.

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    return YES;
    }

As soon as I removed this the program worked as expected.

How would this prevent the actions from working?


#10

Ah, yes, thank you, I’ll add that to the list.

It prevents things from working because it creates another window and places it on top of the window you get from the XIB file. This window is transparent and will eat the touches of the window beneath it. In other words, you have two windows and you can’t interact with the one from the XIB file.


#11

Excellent! Thanks much for the help.


#12

Well done Joe, for fixing up the template for our use. Now that you have one suitable for the exercises in the book, could you post it somewhere for downloading? Perhaps I should be able to follow the instructions, but I can’t even get started with step one, since I don’t know which 4.2 template you started with. And I’m sure I’ll have a dozen more problems after that, being so new to stuff. The template would be extremely useful to readers, since the Style Choices section mentioned it is the basis of most projects in the book.

Someone on the Apple forums unapologetically suggested starting with an Empty app, and Learning all the stuff you need to learn, since you’re going to need to learn it sometime! That sounds like the opposite of your philosophy of concepts introduced as they are needed. I’d like to make it through Chapter 1 without tearing my hair out.


#13

He did; see this announcement.


#14

thanks for posting that link to wrap up this topic.


#15

Hello!

I’ve just purchased your book. I’m very excited to start using it! That said, I’ve been learning Objective-C using another book and I’m quite used to the Xcode 4.2 interface (hence my not using 4.0, 4.1, etc).

My question is about step 5:

How do I do that? In the book it says I may feel like a monkey copying code (which I do), but this set of instructions seems to assume a higher level of competence than that of a monkey. Help!

Many thanks,
-Aeryk


#16

To add the NSObject:

Select the .xib file. In View > Utilities > Object Library, search for an NSObject (using the search box at the very bottom), and drag the Object to the Objects section of the gutter (or whatever you want to call the thing that lists the contents of the .xib).

To change the custom class:

Select the new NSObject, then View > Utilities > Identity Inspector. In the Custom Class section at the top, change the class to QuizAppDelegate.

For the monkey feeling (which I’m guessing a lot of people get initially; I did as well), the important thing is that your brain gets used to the pattern and relays this to your fingers, so after awhile you’re like “Yeah, yeah; create the IBOutlets, create and synthesize the properties, add the IBActions, make the connections…I could do this in my sleep.” That’s the point of actually doing it.

You COULD just copy-and-paste the code from the solution code, or worse, just sit back in your easy chair and read the book with no hands-on time. After all, it would mostly make sense. But then when you sat down to actually create your own app, you’d be lucky to get even the initial Quiz app working without going back to the book.


#17

Thank you so much! I appreciate the need for the monkey-see approach, I was just COMPLETELY stuck on how to add the NSObject. Thanks for clarifying! I’m off to code! :wink:


#18

Is there an update on this issue. Xcode 4.2 is now out of beta and released along with iOS 5. I have just installed and also found no Window-based template for iOS. Every iOS book or class I have been through uses the Window-based template for the majority of projects. I have almost completed the Stanford CS193 course on iTunes U and they used it almost exclusively. Has anyone raised this with Apple? Have they acknowledged the issue? I have seen a number of comments telling people not to use beta code but now it is in GA everyone will be using it. I was forced to upgrade following the Lion upgrade as Xcode 4.0 will not run on Lion.

Surely the right approach is to find out why it has been dropped and if it can be added back? I can’t believe that a template that appears to be so commonly used was just dropped by Apple without warning. I have found a number of posts on the internet asking why it is missing and no answers anywhere.


#19

Ok, so I have read the comments suggesting we raise this as a bug with Apple so I went to the section of their site where you log bugs and I got an error message say there was a bug with the bug reporter, this is getting silly. For some reason I can’t get onto the developer forums either. I feel like I am going crazy. Is anyone else having similar problems.

I can’t get past this screen - developer.apple.com/devforums/


#20

I just started going through this book today and was disappointed, it is already out of date. :imp: I am not sure who to be more annoyed at, the authors for putting out a “second” edition so close to the release of a new iOS version or Apple for changing their new project template.

I am not sure why you would tell us to turn off the ARC? From everything i have read on Apple this seems to be a tremendous improvement, am i missing something? Can’t we just ignore all the allocation/deallocation instructions in the book?