• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: make connections without InterfaceBuilder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make connections without InterfaceBuilder


  • Subject: Re: make connections without InterfaceBuilder
  • From: Mario Kušnjer <email@hidden>
  • Date: Mon, 15 Feb 2010 15:09:34 +0100

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 email@hidden +385957051982 mariokusnjer (at) Skype



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Re: make connections without InterfaceBuilder (From: Mario Kušnjer <email@hidden>)

  • Prev by Date: NSView : Background bitmap drawing issue
  • Next by Date: Re: NSBrowser Question
  • Previous by thread: Re: make connections without InterfaceBuilder
  • Next by thread: Older version of spotlight importer plugin still seen by mdimport -L
  • Index(es):
    • Date
    • Thread