Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 31, 2008, 04:42 AM   #1
DeDMakar
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
How correctly to use my class in main.m?

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]; // How it is correct????
    return NSApplicationMain(argc,  (const char **) argv);
}
I want that method InitForm was processed at start of the project(application).
Thanks...

Last edited by DeDMakar; Mar 31, 2008 at 05:17 AM.
DeDMakar is offline   0 Reply With Quote
Old Mar 31, 2008, 08:30 AM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: 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.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Apr 2, 2008, 03:53 AM   #3
DeDMakar
Thread Starter
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
Quote:
Originally Posted by Sayer View Post
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.
DeDMakar is offline   0 Reply With Quote
Old Apr 2, 2008, 08:09 AM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Apr 4, 2008, 05:08 AM   #5
DeDMakar
Thread Starter
macrumors member
 
Join Date: Mar 2008
Send a message via ICQ to DeDMakar Send a message via Skype™ to DeDMakar
I use method awakeFromNib.
Code:
-(void)awakeFromNib
{
	[image setImage:[NSImage imageNamed:@"apple_big.jpg"]];
	[textfield setStringValue:[NSString stringWithFormat:@"User: %@", NSUserName()]];
}
DeDMakar is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
The Java class file "xxx.class" could not be launched. piratemacfan Mac Applications and Mac App Store 1 Aug 31, 2013 03:24 PM
The Java class file "PopSampleApplet.class" could not be launched. piratemacfan OS X 10.8 Mountain Lion 0 Aug 30, 2013 03:03 PM
Referencing a child class in a parent class, good or bad? SAIRUS iPhone/iPad Programming 11 Aug 28, 2013 11:59 AM
Changing the Main User on OSX and Removing the Old Main User Biggles-90 OS X 4 Oct 30, 2012 10:59 PM
Difference between Public class and private class. zijianz iPhone/iPad Programming 4 Jun 29, 2012 09:29 PM

Forum Jump

All times are GMT -5. The time now is 10:16 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC