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

big_malk

macrumors 6502a
Original poster
Aug 7, 2005
557
1
Scotland
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?
 
I think you need to declare actions and/or outlets for your class..
http://developer.apple.com/documentation/DeveloperTools/Conceptual/IB_UserGuide/CodeIntegration/CodeIntegration.html


Sorry I cant be of more help as I read chapter 1 of "Beginning iPhone Develpoment".... and then just skipped to the chapter on OpenGL.... but the Actions and Outlets stuff seems to ring a bell regarding your problem.

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...
 
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.
 
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.

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 :)

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

Also, by convention class names are capitalized: Person.

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...?
 
It should be [name release] instead. That code would most likely crash on you in most cases :)
 
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...?

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.