Saludos.


Manuel,
Lo has creado desde un NIB ? Eso es formidable! ![]()
Quedamos ansiosos por que nos muestres algo de c贸digo ![]()
Aclaraci贸n para quienes lean esto:
Los ficheros NIB (Next Interface Builder) son equivalentes a los ficheros RC pero almacenan much铆sima m谩s informaci贸n. Se contruyen con el programa "Interface Builder" que proporciona Apple.
La palabra "Next" y NS ("Next Step") provienen de los ordenadores que cre贸 Steve Jobs cuando le "echaron" de Apple. Posteriormente Apple le compr贸 su tecnolog铆a y se mantuvieron las siglas "NS" de "Next Step". Todo el API del Mac usa el prefijo "NS" de dichos ordenadores "Next Step" (siguiente paso).
Efectivamente el panel esta construido con Interface builder y llamado desde codigo para mostrarse . El problema es que no consiguo cambiar las propiedades despues desde codigo ni llamar a los botones y sus acciones ( por lo menos de momento ) . Aunque si consiguo mostrarlo me parece que por donde he ido no es el camino .... Seguir茅 con ello .
La manera de hacerlo es crear un nib con una ventana yllamarla MainMenu .Colocarlo dentro de Contens-> resources->English.lproj.
Para llamarlo con esta simple funcion vale :
HB_FUNC( WINDOWCONTROLCREATE ) // hWnd
{
NSWindowController * mynibWindow = [[NSWindowController alloc]
initWithWindowNibName:@"MainMenu"];
// hb_retnl( ( LONG ) mynibwindow);
[mynibWindow showWindow: nil];
}
Manuel,
Eso est谩 super bien!!! ![]()
El que no reaccione es normal porque hay que construir una clase controladora derivada que haremos que rute a FiveMac ![]()
Tambien podemos hacer que el nombre del nib se reciba como par谩metro.
Voy a probarlo! ![]()
#import <Cocoa/Cocoa.h>
#define HB_DONT_DEFINE_BOOL
#include <hbapi.h>
@interface WindowController : NSWindowController
{
}
- ( void ) windowDidLoad;
@end
@implementation WindowController
- ( void ) windowDidLoad
{
聽 聽NSArray * controls = [ [ [ self window ] contentView ] subviews ];
聽 聽int i;
聽 聽
聽 聽NSRunAlertPanel( @"windowDidLoad", @"", @"OK", NULL, NULL );
聽 聽
聽 聽if( [ controls count ] == 0 )
聽 聽 聽 NSRunAlertPanel( @"no hay controles", @"", @"OK", NULL, NULL );聽 聽
聽 聽聽
聽 聽for( i = 0; i < [ controls count ]; i++ )
聽 聽 聽 NSRunAlertPanel( @"control", @"", @"OK", NULL, NULL ); 聽
聽 聽 聽
}
@end
HB_FUNC( WINDOWCONTROLLERCREATE )
{
聽 聽NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
聽 聽WindowController * wndController = [ [ WindowController alloc ] initWithWindowNibName : string ];
聽 聽[ wndController showWindow : nil ];
聽 聽聽
聽 聽hb_retnl( ( LONG ) wndController );聽
}El problema es que el dato window es nil...
Did you remember to hook up the window in the nib to File's Owner's
window outlet? Did you remember to change the class identity of File's
Owner to your NSWindowController subclass?





------ editado ----------
Llego tarde .... olvidar lo de abajo .
Antonio me he encotrado esto en cocoabuilders :
Cocoabuilder
cocoa xcode
NSWindowController window always nil?
*
Luc Vandal NSWindowController window always nil? Apr 25 2005, 16:41
Hi,
I can't figure out why [self window] always return nil, even if the
window has already been displayed. Am I missing something?
Thanks!
Luc
*
j o a r Re: NSWindowController window always nil? Apr 25 2005, 16:52
On 2005-04-25, at 16.41, Luc Vandal wrote:
> I can't figure out why [self window] always return nil, even if the
> window has already been displayed. Am I missing something?
Have you dragged the connection from the window controller (files
owner) and the window in the nib file?
j o a r
*
Luc Vandal Re: NSWindowController window always nil? SOLVED Apr 25 2005, 17:30
Yeah that was the problem... thanks! <!-- s:) --><img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" /><!-- s:) -->
On 25-Apr-05, at 10:52 AM, j o a r wrote:
>
> On 2005-04-25, at 16.41, Luc Vandal wrote:
>
>> I can't figure out why [self window] always return nil, even if the
>> window has already been displayed. Am I missing something?
>
> Have you dragged the connection from the window controller (files
> owner) and the window in the nib file?
>
> j o a r
>
> show quoted text
HB_FUNC( WINDOWCONTROLLERCREATE )
{
聽 聽NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
聽 聽NSWindowController * wndController = [ [ NSWindowController alloc ] initWithWindowNibName : string ];
聽 聽
聽 聽if( [ wndController window ] != nil )
聽 聽聽 聽NSRunAlertPanel( @"ventana accesible", @"", @"OK", NULL, NULL );
聽 聽聽
聽 聽hb_retnl( ( LONG ) wndController );聽
}HB_FUNC( WINDOWCONTROLLERCREATE )
{
聽 聽NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
聽 聽NSWindowController * wndController = [ [ NSWindowController alloc ] initWithWindowNibName : string ];
聽 聽NSArray * controls = [ [ [ wndController window ] contentView ] subviews ];
聽 聽int i;
聽 聽 聽
聽 聽for( i = 0; i < [ controls count ]; i++ )
聽 聽 聽 NSRunAlertPanel( [ [ controls objectAtIndex : i ] className ], @"", @"OK", NULL, NULL ); 聽 聽聽
聽 聽
聽 聽hb_retnl( ( LONG ) wndController );聽
}


NSWindowController * mynibWindow = [[NSWindowController alloc] initWithWindowNibName:@"MainMenu"];
[mynibWindow showWindow: nil];
NSWindow * ventana = [mynibWindow window] ;
[ ventana setTitle: @"Hola" ] ;#import <Cocoa/Cocoa.h>
#define HB_DONT_DEFINE_BOOL
#include <hbapi.h>
// NSView * GetView( NSWindow * window );
@interface WindowController : NSWindowController
{
}
- ( void ) BtnClick : ( id ) sender;
@end
@implementation WindowController
- ( void ) BtnClick : ( id ) sender;
{
聽 聽NSRunAlertPanel( @"click", @"", @"OK", NULL, NULL );聽 聽
}
@end
HB_FUNC( WINDOWCONTROLLERCREATE )
{
聽 聽NSString * string = [ [ [ NSString alloc ] initWithCString: ISCHAR( 1 ) ? hb_parc( 1 ) : "" ] autorelease ];
聽 聽WindowController * wndController = [ [ WindowController alloc ] initWithWindowNibName : string ];
聽 聽NSArray * controls = [ [ [ wndController window ] contentView ] subviews ];
聽 聽int i;
聽 聽 聽
聽 聽for( i = 0; i < [ controls count ]; i++ )
聽 聽{
聽 聽 聽 NSControl * control = [ controls objectAtIndex : i ];
聽 聽 聽 NSString * className = [ control className ];
聽 聽 聽
聽 聽 聽 if( [ className isEqual : @"NSButton" ] )
聽 聽 聽 {
聽 聽 聽 聽 聽NSButton * button = ( NSButton * ) control;
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽[ button setAction : @selector( BtnClick: ) ];
聽 聽 聽 } 聽 聽 聽 聽 聽 聽
聽 聽} 聽 聽 聽 聽 聽 聽聽 聽
聽 聽
聽 聽hb_retnl( ( LONG ) wndController );聽
}
NSView * myview = [ventana contentView ] ;
[[myview viewWithTag :255 ] setTitle: @"Hola" ] ;
NSView * myview = [ventana contentView ] ;
[[myview viewWithTag :255 ] setTitle: @"Hola" ] ;
NSButton * boton = ( NSButton * ) [myview viewWithTag :255 ];
[ boton setAction : @selector( BtnClick: ) ];