Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
I need help porting my Mac OS X app into an Iphone app! Here is my app controller.h

Code:
@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;
@end


and here is my appcontroller.m

Code:
@implementation DoorController

- (void)awakeFromNib {
	srandom(time(NULL));
	[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]];
		wrongCount++;
		[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]];
	}

	
	
}
@end


What needs to change?
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
The only things I can see is that NSTextField will need to be changed to UILabel and used like [labelname setText:mad:"Blah"] as opposed to [labelname setStringValue:mad:"Blah"]
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
do you think i made the wrong kind of iphone app? i picked "view-based app"
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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.
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
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?
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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 ;)
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
lol sorry! im really new at this. i still have no idea what i did wrong whatsoever.
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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 :eek:
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
mhhh i dont know whats wrong. i checked if all my connections were there, and they were...

Does anyone know what the problem is?
 

mccannmarc

macrumors 6502
Aug 15, 2008
270
0
Manchester, UK
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 :eek:
 

eddietr

macrumors 6502a
Oct 29, 2006
807
0
Virginia
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.
 

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
one more queston :D


How can i save the highScores variable into my plist?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.