Noob Q - Objects not loading in interface builder

Discussion in 'iOS Programming' started by big_malk, May 9, 2009.

  1. big_malk macrumors 6502a

    Joined:
    Aug 7, 2005
    Location:
    Scotland
    #1
    I've been a web developer for a while now, and I thought I'd try my hand at developing for iPhone, but I'm stumped at the first thing I'm trying :(

    I'm watching lectures from the Stanford Uni iPhone class, and I'm trying a very basic example using this code...

    person.h
    Code:
    #import <Foundation/Foundation.h>
    
    @interface person : NSObject {
    	NSString *name;
    }
    
    - (NSString *)name;
    - (void)setName:(NSString *)value;
    
    @end
    person.m
    Code:
    #import "person.h"
    
    @implementation person
    
    - (NSString *)name {
    	return name;
    }
    
    - (void)setName:(NSString *)value {
    	if (value != name) {
    		[value release];
    		name = [value copy];
    	}
    }
    
    @end
    The 'person' object isn't showing up at all in interface builder, so I can't link any buttons to it. Their showing up in the 'Project symbols' collection, and the interface builder window shows it's linked to the Xcode project properly, I've tried manually loading class files etc... what am I missing here?
     
  2. BananaDuffle macrumors member

    Joined:
    Mar 29, 2009
    #2
  3. big_malk thread starter macrumors 6502a

    Joined:
    Aug 7, 2005
    Location:
    Scotland
    #3
    Thanks, but I don't think that’s it. In the demonstration I watched and from what was said, with just the code I have, I should get a 'person' object in interface builder, then choose the existing method 'setName' as the action for a button or whatever. Although it would seem I have missed/misunderstood something along the way...
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    You normally use IB for view classes and view controller classes. Your person class is a data model class.

    I'm not sure why you would want to connect a button to a data object.

    BTW, there's a bug in your setPerson method.

    Also, by convention class names are capitalized: Person.
     
  5. big_malk thread starter macrumors 6502a

    Joined:
    Aug 7, 2005
    Location:
    Scotland
    #5
    I know, but at this point I'm just trying to get familiar with the tools and the language, I'm not really trying to achieve anything spectacular... yet ;). Making an app that does *anything* when I click a button would be an achievement for me at this stage :)

    I don't have a 'setPerson' method :p if you mean 'setName', could it be that [value release] comes before name = [value copy]? That seemed to be the wrong way round to me, but that’s what the example said so I went with it :confused:
    If that's not it, care to help by telling me what it is, since I've obviously not seen it myself...?
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    It should be [name release] instead. That code would most likely crash on you in most cases :)
     
  7. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #7
    well, maybe you don't want to to something special, but you can't display something on something that isn't a subclass of UIView.
    You can make the "Person"-Class appear in IB by simply creating an object (by dragging an "object" from the library to your IB file) and giving it the class "Person" - which will make it a "Person" object. But you cannot display buttons on this Person object because it is no subclass of UIView! simply won't work!

    oh and btw: cocoa touch can automatically create the "accessor methods" (so the stuff you wrote above for your name-property) for you. just in case you didn't know, I guess you wrote those methods yourself for training purposes
     
  8. big_malk thread starter macrumors 6502a

    Joined:
    Aug 7, 2005
    Location:
    Scotland
    #8
    *snipped

    Sorry, got it, ignore me, I'll go away now
     

Share This Page