Accessing cocoa interface builder controller methods
So I have an objective-c project that uses a controller class. This interfaces with interface builder via 开发者_开发技巧IBOutlets.
My understanding is that the controller gets initialized by loading the user interface (as it is added to interface builder as an object). I would then like to use the controller's getter methods to return values that are in the IBOutlet fields.
So, to clarify what I mean with some code, here's my controller interface/implementation:
@interface controller : NSObject {
@private
IBOutlet NSTextField *name;
}
-(NSString*) name;
@end
Then, in my implementation, I have:
-(NSString*) name
{
return [name stringValue];
}
in a third class, I'd like to be able to write:
NSString blahblah = [controller name] and have the value of blahblah assume the value of whatever is in the controller's IBOutlet "name" field.
Hopefully this makes sense. When I try and do it this way I get "Semantic Issue: Method '+name' not found (return type defaults to 'id')"
Why? Where is the controller object actually substantiated and where, and how do I access it's fields?
You have to instantiate the controller by using [[controller alloc] initWithNibName:nibName bundle:nil];
By just using [controller name] you are calling a class method. Also it should be NSString *blahblah
You should read this document: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html#//apple_ref/doc/uid/TP40007594
精彩评论