View Full Version : Can someone help me port from leopard to iphone OS

Apr 11, 2009, 03:24 PM
I need help porting my Mac OS X app into an Iphone app! Here is my app controller.h

@interface DoorController : NSObject {
int level;
int highScore;
int wrongCount;

IBOutlet NSTextField *levelLabel;
IBOutlet NSTextField *scoreLabel;
IBOutlet NSTextField *successLabel;
IBOutlet NSTextField *wrong;

- (IBAction)resetDoor:(id)sender;
- (IBAction)clickDoor:(id)sender;
- (void)setLevel:(int)newLevel withMessage:(NSString *)message;

and here is my appcontroller.m

@implementation DoorController

- (void)awakeFromNib {
[self setLevel:1 withMessage:nil];

- (IBAction)clickDoor:(id)sender {
int correctDoor = random() % 3 + 1;
(correctDoor == [sender tag])
[self setLevel]:level + 1 withMessage:[NSString stringWithFormat:@"You passed! Welcome to level %i!", level + 1]];
else {
[self setLevel:1 withMessage:[NSString stringWithFormat:@"Sorry, you failed! The correct door was door #%i!", correctDoor]];
[wrong setStringValue:[NSString stringWithFormat:@"In this session you have gotten %d wrong", wrongCount]];

- (void)setLevel:(int)newLevel withMessage:(NSString *)message {
level = newLevel;
[levelLabel setStringValue:[NSString stringWithFormat:@"Level %i", level]];

if (message)
[successLabel setStringValue:message];

if (level > highScore) {
highScore = level;
[scoreLabel setStringValue:[NSString stringWithFormat:@"High Score: %i", highScore]];


What needs to change?

Apr 11, 2009, 04:07 PM
The only things I can see is that NSTextField will need to be changed to UILabel and used like [labelname setText:@"Blah"] as opposed to [labelname setStringValue:@"Blah"]

Apr 11, 2009, 04:12 PM
The only things I can see is that NSTextField will need to be changed to UILabel...
Actually, wouldn't the equivalent be UITextField?

Apr 11, 2009, 04:18 PM
Actually, wouldn't the equivalent be UITextField?

Probably so but for the reason I can see the NSTextFields are being used a UILabel would suffice. Good one for pointing that out though it didn't even cross my mind

Apr 11, 2009, 04:19 PM
hmmm its still not working... do you mind looking at my code?


And thanks for the replies!

Apr 11, 2009, 04:25 PM
do you think i made the wrong kind of iphone app? i picked "view-based app"

Apr 11, 2009, 04:39 PM
http://repo.dude-ware.co.uk/Doors modded.zip

sorted, there are still 2 warnings because some methods are not there and I had 1 error because i dont have the picture file on my desktop (make sure to always select to copy the files into the applications directory rather than just refer to the files when importing them to your project) but that should do the trick.

Apr 11, 2009, 04:48 PM
Hey thanks!

Well its weird... Im not getting any errors with the code. But when i run the app, and click a button, it freezes. Whats wrong?

Apr 11, 2009, 04:58 PM
If you look in the console log after it has crashed is says:-

2009-04-11 22:57:03.507 Doors[9699:20b] *** -[UILabel clickDoor:]: unrecognized selector sent to instance 0x522c00

That should be enough info for you ;)

Apr 11, 2009, 05:04 PM
lol sorry! im really new at this. i still have no idea what i did wrong whatsoever.

Apr 11, 2009, 05:11 PM
Ok no problem, to be honest I know next to nothing about IB, I code all my UI stuff. The use of IBOutlets and IBActions is pretty much alien to me. You are probably better waiting for someone to look over your code with more IB experience than myself as I suspect your problem could be with the fact that you are trying to set the values of the labels directly when they are part of your xib. Just a thought but do you not need to at least @property them and @synthesize them to modify their values in code?

As you can see though the code I fixed for you was basic structural stuff so that should all work properly once you have this issue fixed :o

Apr 11, 2009, 05:25 PM
mhhh i dont know whats wrong. i checked if all my connections were there, and they were...

Does anyone know what the problem is?

Apr 11, 2009, 05:30 PM
I just edited my post just before you replied as I had a rethink...lol I'm going to take that file off my server now so you are probably best uploading that one I modded to your mediashare for everyone else to use :o

Apr 11, 2009, 05:36 PM
kk thanks for the help man!

Well if anyone can help me, please do!

If you need the app, its here...


Apr 11, 2009, 05:38 PM
no problem mate, sorry I couldn't help you anymore :o I HATE IB with a passion so my experience is pretty much limited to code lol

Apr 11, 2009, 06:54 PM
np its fine lol

well if anyone can help, link is here

Apr 11, 2009, 08:09 PM
Well, your connections are not correct. First, you have two instances of your view controller in the two nibs. The first instance is in the main nib. It will load the second nib, so you don't want to create another of that view controller in the second nib.

So delete that instance and make your connections to File's Owner instead. File's owner will be the view controller instance from the main nib.

Hope that helps.

Apr 11, 2009, 09:08 PM

Thanks for the replies everyone!

Apr 11, 2009, 09:10 PM
one more queston :D

How can i save the highScores variable into my plist?