Re: Write app without nib file.
Re: Write app without nib file.
- Subject: Re: Write app without nib file.
- From: Jeff Johnson <email@hidden>
- Date: Fri, 3 Oct 2008 13:54:17 -0500
Daniele,
My suspicion is that the issue has nothing to do with whether or not
you have a nib.
The code below won't work, because as far as I can tell, you never
add the view to a window. A view needs to be in a window to receive
events.
By the way, it's standard Cocoa naming convention to capitalize class
names -- MyView rather than myView. It's a good idea to follow
standard Cocoa naming conventions, especially when other people will
read your code.
-Jeff
On Oct 3, 2008, at 9:06 AM, Daniele Basile wrote:
Hi,
I want to write an application without using a nib file.
I found same code that do this and it works, but I am not able to
manage
event. For exactly I want to trap some event (tablet event) and
manage this.
So, I write this code:
- main.m -------------------------------------
import <Cocoa/Cocoa.h>
#import "myView.h"
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *window;
myView *view;
view = [[myView alloc] initWithFrame:NSMakeRect(0,100,200,200) ];
window = [[NSWindow alloc] initWithContentRect:NSMakeRect
(50,100,200,300)
styleMask:NSTitledWindowMask | NSResizableWindowMask
backing:NSBackingStoreBuffered
defer:TRUE];
NSButton *button=[[NSButton alloc]initWithFrame:NSMakeRect
(10,10,180,32) ];
[button setBezelStyle:NSRoundedBezelStyle];
[button setTitle:@"Quit"];
[button setTarget:NSApp];
[button setAction:@selector(terminate:)];
[[window contentView] addSubview:button];
[NSApplication sharedApplication];
[window makeKeyAndOrderFront: nil];
[pool release];
[NSApp run];
return 0;
}
-----------------------------------
- myView.h ----------------------------------
#import <Cocoa/Cocoa.h>
@interface myView : NSView
{
}
- (id)initWithFrame:(NSRect)frame;
- (BOOL)acceptsFirstResponder;
- (void)tabletProximity:(NSEvent *)theEvent;
@end
-----------------------------------
- myView.m ------------------------------------------
#import "myView.h"
@implementation myView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
printf("Parto..\n");
}
return self;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (void)tabletProximity:(NSEvent *)theEvent
{
printf("prossimita'\n");
if([theEvent isEnteringProximity])
{
printf("Entro\n");
printf("capabilityMask(%d)\n", [theEvent capabilityMask]);
printf("deviceID(%d)\n", [theEvent deviceID]);
printf("enterProximity(%d)\n", [theEvent isEnteringProximity]);
printf("pointerID(%d)\n", [theEvent pointingDeviceID]);
printf("pointerSerialNumber(%d)\n", [theEvent
pointingDeviceSerialNumber]);
printf("pointerType(%d)\n", [theEvent pointingDeviceType]);
printf("systemTabletID(%d)\n", [theEvent systemTabletID]);
printf("tabletID(%d)\n", [theEvent tabletID]);
printf("uniqueID(%d)\n", [theEvent uniqueID]);
printf("vendorID(%d)\n", [theEvent vendorID]);
printf("vendorPointerType(%d)\n", [theEvent
vendorPointingDeviceType]);
}
else
{
printf("Esco\n"); }
}
@end
--------------------------------------------------
This code draw a window with one button that, I press it, the
program quit.
I see the window and button work, but the myView class seem not
receive the windows events..
Have any idea for this?
Thanks
Daniele.
_______________________________________________
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