Can someone help me port from leopard to iphone OS

Discussion in 'iOS Programming' started by gizabo, Apr 11, 2009.

  1. macrumors regular

    Joined:
    Jul 20, 2008
    #1
    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?
     
  2. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #2
    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"]
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Actually, wouldn't the equivalent be UITextField?
     
  4. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #4
    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
     
  5. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #5
  6. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #6
    do you think i made the wrong kind of iphone app? i picked "view-based app"
     
  7. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #7
    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.
     
  8. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #8
    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?
     
  9. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #9
    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 ;)
     
  10. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #10
    lol sorry! im really new at this. i still have no idea what i did wrong whatsoever.
     
  11. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #11
    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:
     
  12. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #12
    mhhh i dont know whats wrong. i checked if all my connections were there, and they were...

    Does anyone know what the problem is?
     
  13. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #13
    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:
     
  14. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #14
  15. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #15
    no problem mate, sorry I couldn't help you anymore :eek: I HATE IB with a passion so my experience is pretty much limited to code lol
     
  16. thread starter macrumors regular

    Joined:
    Jul 20, 2008
  17. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #17
    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.
     
  18. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #18
    YEAA THANKS!

    Thanks for the replies everyone!
     
  19. thread starter macrumors regular

    Joined:
    Jul 20, 2008
    #19
    one more queston :D


    How can i save the highScores variable into my plist?
     

Share This Page