Forum Navigation
Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: fbcocoaTutorial_1
You need to log in to create posts and topics.

Tutorial_1

Posted by: svanvoorst <svanvoorst@...>

This demo creates a basic window to which we can start adding controls.  To create demos/applications in obj-c, we need 3 files: .h, .m, and main.  FB takes care of the details for us automatically if we follow this template:

'----- begin -----

BeginCDeclaration
//@end // interface
EndC
BeginCFunction
//@end //implementation
EndC
BeginCCode
{
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
 
  [NSApplication sharedApplication];
  [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
    id menubar = [[NSMenu new] autorelease];
    id appMenuItem = [[NSMenuItem new] autorelease];
    [menubar addItem:appMenuItem];
    [NSApp setMainMenu:menubar];
    id appMenu = [[NSMenu new] autorelease];
    id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
        action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
    [appMenu addItem:quitMenuItem];
    [appMenuItem setSubmenu:appMenu];
   #define _wndW  430
   #define _wndH  300
    id window = [ [ NSWindow alloc ] 
                       initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
                       styleMask: NSClosableWindowMask | NSTitledWindowMask
                       backing:NSBackingStoreBuffered
                       defer:NO];
    [window center];
    [window setTitle: @"NSWindow" ];
    [window makeKeyAndOrderFront:nil]; 
  [NSApp activateIgnoringOtherApps:YES];
  [NSApp run];
  [pool drain];
  return NSApplicationMain(argc,  (const char **) argv);
}
EndC
'----- end -----
BeginCDeclaration...EndC becomes the .h file.  BeginCFunction...EndC becomes the .m file combined with main, which is created from BeginCCode...EndC.  Succeeding tutorials will build on this template; it will be used repetitively.
Sources of information: 1) XCode Documentation  2) Apple PDF files  3) Google  4) Books  5) Hopefully this List in the future
Steve Van Voorst


To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]