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

DeDMakar

macrumors member
Original poster
Mar 24, 2008
39
0
How correctly to use my class in main.m? Project - Cocoa Application.
Class:
Code:
//  "InitFormApp.h"

#import <Cocoa/Cocoa.h>

@interface InitFormApp : NSObject {
IBOutlet NSTextField *textfield;
IBOutlet NSImageView *image;
}
-(id)InitForm;
@end


Code:
// "InitFormApp.m"

#import "InitFormApp.h"

@implementation InitFormApp
-(id)InitForm
{
	[super init];
	[image setImage:[NSImage imageNamed:@"apple_big.jpg"]];
	[textfield setStringValue:[NSString stringWithFormat:@"User %@", NSUserName()]];
	return self;
}
@end

Code:
//  "main.m"


#import <Cocoa/Cocoa.h>
#import "InitFormApp.h"

int main(int argc, char *argv[])
{
    InitFormApp *initus = [InitFormApp InitForm]; // [COLOR="Red"]How it is correct????[/COLOR]
    return NSApplicationMain(argc,  (const char **) argv);
}

I want that method InitForm was processed at start of the project(application).
Thanks...
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
Take a look at the Example projects in Developer > Examples > AppKit.

The SimpleTemperatureConverter project is a good starting point. And then look at SimpleBrowser.
 

DeDMakar

macrumors member
Original poster
Mar 24, 2008
39
0
Take a look at the Example projects in Developer > Examples > AppKit.

The SimpleTemperatureConverter project is a good starting point. And then look at SimpleBrowser.

I must use initialize method of NSObject? But this method can not use IBOutlet and other variables, who are registered ".h" file.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
In your MainMenu.nib, you need to create an instance of your InitFormApp object there and connect your IBOutlets. Back in your code, remove your line of code in main.m, and move your code from InitForm to awakeFromNib.

You may also want to read The Nib Object Life Cycle.
 

DeDMakar

macrumors member
Original poster
Mar 24, 2008
39
0
I use method awakeFromNib.
Code:
-(void)awakeFromNib
{
	[image setImage:[NSImage imageNamed:@"apple_big.jpg"]];
	[textfield setStringValue:[NSString stringWithFormat:@"User: %@", NSUserName()]];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.