Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Beginning iOS Game Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning iOS Game Development
This is the forum to discuss the Wrox book Beginning iOS Game Development by Patrick Alessi ; ISBN: 978-1-1181-0732-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS Game Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 5th, 2012, 01:11 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Location: Singapore
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 - SampleUI program

I'm really stuck with the very first program I tried for iOS.
I followed all the instructions from page 37 onwards, and when I came to page 40, items 18 & 19 i got a warning when entering 'mySlider.value' saying mySlider was undeclared.

I then went to look at the sample code I downloaded from WROX and found that in the implementation file there was no @synthesize for 'mySlider'

I corrected my own code following all the files from the download and ran the program.

The build succeeded but when the iPhone simulator started the program wouldn't load and I noticed an error message in 'main.m':
'Thread 1: signal SIGABRT'

I finally decided to run the downloaded code and apart from a modification that was needed (with the latest Xcode 4.5.2) it ran.

Why were there so many lines of codes missing in my code when compared with the one I downloaded???

I reread and reread everything from page 37 to 40 and I even redid the whole exercise from scratch after trashing the original project.

Without success

This is my very first program for iOS following the book, and I'm not impressed...
Reply With Quote
  #2 (permalink)  
Old November 5th, 2012, 06:46 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Location: Singapore
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I managed to make it work by having the 'program name" prefix added in front of my files.

I noticed that all books on Objective C and iOS programming show the files with the program name in front.
When I start a new project e.g. iOSTest in XCode, my ViewController.h and .m are just that: ViewController.h & ViewController.m

When I add the iOSTest in front (i.e. iOSTesViewController.h & .m) the program worked.

And i realize I have to fill in the prefix when I start a new project (in the window where you name the program)

The book doesn't mention it, neither does any other book mention it. Unless...there is a preference somewhere that does it automatically??

Last edited by straycatsgp; November 5th, 2012 at 06:47 AM. Reason: correction
Reply With Quote
  #3 (permalink)  
Old November 5th, 2012, 11:06 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

There are elements of style for Objective C coding that have changed since the publication of the book. Also, the templates that Xcode provides have changed to reflect the new approach. Unfortunately the text and the download for this example are not congruent.

For example there is no longer an @interface block in the template (no curly braces). Only @property declarations are placed in the header. Private variables are placed in the implementation file in a category. The curly braces can be added and variables declared, but that runs in conflict with the OOP concept of encapsulation which the new format tries to enforce.

Using the current format the .h file looks like this:
Code:
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
- (IBAction)buttonPressed:(id)sender;
@property (weak, nonatomic) IBOutlet UISlider *mySlider;
- (IBAction)sliderMoved:(id)sender;

@end
In the .m file template at the top there is a category for adding internal (private) variables; in this case the int counter; variable.

Code:
#import "ViewController.h"

@interface ViewController ()
{
    int counter;
}

@end
The implementation follows:

Code:
@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    counter = 0;
    self.myLabel.text = [[NSNumber numberWithInt:counter] stringValue];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)buttonPressed:(id)sender {
    counter++;
    self.myLabel.text = [[NSNumber numberWithInt:counter] stringValue];
    self.mySlider.value = counter;
    
}
- (IBAction)sliderMoved:(id)sender {
    counter = self.mySlider.value;
    self.myLabel.text = [[NSNumber numberWithInt:counter] stringValue];
}
@end
There is no need to add prefixes as you concluded. There is likely another subtle error in what you have done.

Here is a link to the full project.
http://db.tt/Lun5utU5

Bob
Reply With Quote
  #4 (permalink)  
Old December 19th, 2012, 01:57 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi. I'm really having trouble with this... It looks right but it's not working right.

https://www.dropbox.com/sh/4620qb8phe841kv/boTiwWm0b3

It's under 'SampleUI_notWorking'
Reply With Quote
  #5 (permalink)  
Old December 19th, 2012, 11:52 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

It appears that you made more than one attempt to create your outlet connections, first with one name - Label, Press and Slider which do not exist as properties in the ViewController.h, but whose connections still exist in the ViewController.xib file, and a second attempt with the names myLabel and mySlider (but nothing for "Press"). The label and slider do need to have outlet connections but the button does not, as used in the program. If you click on the .xib file in the Project navigator then single click on the File's Owner, open the Utilities (right pane in the View) and open the Connections Inspector you will see in the Outlets disclosure these obsolete outlets. The functioning outlets have a black dot indicating the connection, the outlets without pointers have an exclamation point. Those with exclamation points need to be deleted by clicking the "x". This will resolve your problem.

Bob

Also, it would be safer for you, if when sharing files with Dropbox to make direct links to only the files you wish to share. Since Dropbox shares files not folders, you should .zip the project and share only the link to that project rather than exposing your entire Public folder. It is also easier to download the project, since as you currently have it each file individually or the entire Public folder need to be downloaded to get the project.

Last edited by thepianoguy; December 19th, 2012 at 11:58 AM.
Reply With Quote
  #6 (permalink)  
Old January 8th, 2013, 08:27 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Xcode version issues

Hi I picked up this book just recently and I'v already noticed issues starting on page 25. The code the book references is not what I have in my Xcode. I'm using Xcode 4.5.2

Pg 25 has you look at the code in ViewController.m

when I do, I have far far less code in mine then the author refers too. Now reading what is posted here, I'm worried if this book is going to present problems moving forward. I really want to learn Xcode/Object C etc and I was really counting on this book to get me there. The author is working out of Xcode 4.2. So far the book has been great but to hit the wall as soon as you get to learning the code is very discouraging

Should I continue with this book or did I just waste my money? Am I learning old code formats that I shouldn't be? No disrespect to the Author by any means, his style and flow in the book has been great so far but being new to programming I really don't want to start off on the wrong foot sort of speak.
Reply With Quote
  #7 (permalink)  
Old January 8th, 2013, 10:16 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

FX77
Hey! Yeah, there are too many problems with the book, the further along I go into it. Some are really errors (wrong varName, etc.) that the editors didn't pinpoint and correct.

I feel like I've wasted my money on this book although that's not to say I didn't learn anything from it. Fortunately, I know some C++ but I wanted to get more familiar with programming in XCode. My code usually works just fine in Dev-C++ (a free windows SDK)

If you're just out to learn Objective-C though, try "Programming in Objective-C 4th Edition by Stephen G. Kochan"

If you want to make games, maybe Cocos2D is for you.
Reply With Quote
  #8 (permalink)  
Old January 8th, 2013, 10:27 PM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm out to learn Objective C and Cocos2D, from what I understand you need to know both. Wow this is really upsetting to hear. I doubt I can get a refund on the book too, I got it a chapters.ca

First and last Wrox book I buy. :(
Reply With Quote
  #9 (permalink)  
Old March 21st, 2013, 02:24 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there.
I'm new to Xcode and iOS/Objective-C programming.

I'm having trouble with the part of the book as well.

My first problem was when I tried to use mySlider and xCode complained it hadn't been initialised yet. Since myLabel was used as self.myLabel, i tried that and xCode stopped complaining.

However I always get an exception when running this app:
Code:
2013-03-21 15:12:02.420 SampleUI[1477:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x753eae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key buttonPressed.'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1d19fb1 0xb7ae41 0xafc5f8 0xafc0e7 0xb26b58 0x230019 0x10e2663 0x1c8c45a 0x22eb1c 0xf37e7 0xf3dc8 0xf3ff8 0xf4232 0x433d5 0x4376f 0x43905 0x4c917 0x26b5 0x10157 0x10747 0x1194b 0x22cb5 0x23beb 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1117a 0x12ffc 0x23ed 0x2315)
libc++abi.dylib: terminate called throwing an exception
(lldb)
And I just can't seem to find the problem.

I downloaded the project thepianoguy posted and it works. It seems to be identical to my project.
Please help me find the error, this is driving me crazy. The code is identical, I even copy pasted into mine. Is it an error with the project's properties? (if so, should't it be easier to fix this?)
I will continue following this book, even though it seems to have a few errors/is no longer up to date, but if someone can help me pinpoint the error then hopefully I won't make the same mistake again.

Any help will be greatly appreciated.
Here's my project: https://www.dropbox.com/s/il1qxyulom7gflf/SampleUI.zip
Reply With Quote
  #10 (permalink)  
Old March 23rd, 2013, 10:12 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

I downloaded your project and ran it without crashing. (Xcode 4.6.1) (The code appears to be copy and pasted from the project I put up.)
There is an error however, similar to a previous post, since you have outlet connections that go no where. The errors are in the .xib file. Single click on the .xib file and then right (or option) click on Files Owner (the yellow cube). This will bring a window with the outlets and actions. Two outlets, buttonPressed and sliderMoved will show yellow caution triangles. (The button has no need for an outlet since it only sends actions and is not updated in any way by the program. The mySlider outlet handles the updating of the position of the slider when a number is input in the text box. So if you had a "sliderMoved" outlet it would be serving the same purpose as the "mySlider" outlet. You would simply create that property and replace all cases of mySlider with sliderMoved) These outlets are not supposed to be there and are not connected to properties. Single click the 'x' to delete them. This error is most likely to occur if, when using the assistant to generate the property/action, after control dragging in the Popup you do not change the option from outlet to action. This will generate a property obviously, not an action. If the code for this is eliminated (since it serves no purpose and is not in the books code) the .xib will be connected to a nonexistent property (this causes the key value coding error).

Bob
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 Dialog Program cokebootle BOOK: Beginning Android Application Development 5 March 17th, 2012 09:25 AM
chapter 2 Mailing label program. Help! tobbeebbot BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 January 13th, 2012 08:06 AM
the sampleUI example is strange baryonicdm BOOK: Beginning iOS Game Development 2 January 2nd, 2012 01:03 PM
CHAPTER 3 - Outlets and Actions TRY IT OUT program is not working tduraipkt BOOK: Beginning iPad Application Development 2 August 25th, 2010 05:47 AM
Chapter 6 : Message Contract Program Example thsun BOOK: Professional WCF Programming: .NET Dev with Windows Communication Found ISBN: 9780470089842 16 January 11th, 2008 11:34 AM



All times are GMT -4. The time now is 04:30 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.