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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Trying to use my iMac in Target Display Mode InfoTime iMac 13 Dec 6, 2011 08:45 PM
How Long To Download matthew12 Mac OS X 10.7 Lion 2 Nov 30, 2011 05:27 AM
How to make monitor using my MBP the main screen? ReidStylez Mac OS X 10.7 Lion 4 Jul 28, 2011 06:15 PM
How do I use my phone in Australia? AztecKing iPhone Tips, Help and Troubleshooting 4 May 6, 2011 01:24 AM
How to use 24in ACD as main monitor in Bootcamp with MBP Greenhoe Windows, Linux & Others on the Mac 0 Mar 8, 2009 12:24 PM


All times are GMT -5. The time now is 12:08 AM.

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

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