Re: make connections without InterfaceBuilder

2010-02-15 Thread Mario Kušnjer

Hello !

I don't know if this got answered but here is my attempt. It is just a  
basic way of programmatically setting
an object as a application delegate and programmatically creating a  
button on the applications main

window and setting it to perform an action when clicked.

I know that there are some issues about the way this is implemented  
but it points the way to go.

Since I am a newbie my self any suggestions are more than welcome.

Brief explanation follows.

In Interface Builder:
- in MainMenu.xib create generic NSObject by adding it from the Library
- select that NSObject and in the Identity Inspector make it an  
instance of our ApplicationController class

In Xcode:
- in awakeFromNib we make our self as the application delegate
- in applicationDidFinishLaunching: we tell the application to make  
the first window that it finds as main

window, because at this time there is still no main window
- then we create our button instance, set its action as a selector  
with our action method, set our self as a target of that action,
and perform all necessary initializations for our button (title, type,  
etc)

- we add our button on the main window and then release the button
- in dealloc we remove our self as being application delegate
- okButtonAction: is our button's action method that performs NSBeep()  
function


Code follows.


ApplicationController.h

#import Cocoa/Cocoa.h


@interface ApplicationController : NSObject
{

}

@end

ApplicationController.m

#import ApplicationController.h


@implementation ApplicationController

- (void)awakeFromNib
{
[NSApp setDelegate:self];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSApp makeWindowsPerform:@selector(makeMainWindow) inOrder:NO];

	NSButton * okButton = [[NSButton alloc]  
initWithFrame:NSMakeRect(10.0, 10.0, 96.0, 32.0)];

[okButton setAction:@selector(okButtonAction:)];
[okButton setTarget:self];
[okButton setTitle:@OK];
[okButton setButtonType:0];
[okButton setBezelStyle:11];

[[[NSApp mainWindow] contentView] addSubview:okButton];
[okButton release];
}

- (void)dealloc
{
[NSApp setDelegate:nil];

[super dealloc];
}

- (void)okButtonAction:(id)sender
{
NSBeep();
}

@end


Thanks.


Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusnjer (at) Skype



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: make connections without InterfaceBuilder

2010-02-09 Thread Mario Kušnjer


On 2010.02.09, at 08:33, Ian Jackson wrote:

Can I just clarify, are you specifically trying to do this in code  
because you want to, or because you don't know how to make the  
connections in Interface Builder?


In interface builder control drag from the control to the  
appDelegate for the action, and from the AppDelegate to the control  
for the outlet.


Sorry if you already know this.

Ian.

On 9/02/2010, at 5:03 PM, Jonathan Chacón wrote:



Please, read first post. He specifically said that he is blind.  
Obviously, he can't control-drag.


Mario Kušnjer
mario.kusn...@sb.t-com.hr
+385957051982
mariokusnjer (at) Skype



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com