Serveral selectors of my controller are not called
Serveral selectors of my controller are not called
- Subject: Serveral selectors of my controller are not called
- From: Dominik Pich <email@hidden>
- Date: Sun, 25 Jul 2004 21:37:27 +0200
Neither '-dealloc' nor '-windowDidLoad' gets called...
Why is that?
The class is loaded from nib and is the only controller.
Thanks,
Dominik
<code>
#import "ed2kController.h"
#import "ed2kProtocol.h"
#import "ed2kServer.h"
#import "defaults.h"
@implementation ed2kController
/**
* Static method to initialize data for this class
*/
+(void)initialize
{
//ip of first network device is to replace the defaults
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
//set defaults
NSLog( @"set defaults" );
[defaultValues setObject:CDCClientIpValue forKey:CDCClientIp];
[defaultValues setObject:[NSNumber numberWithInt:CDCClientPortValue]
forKey:CDCClientPort];
[defaultValues setObject:[NSNumber
numberWithBool:CDCClientRegisterValue] forKey:CDCClientRegister];
[defaultValues setObject:CDCServerIpValue forKey:CDCServerIp];
[defaultValues setObject:[NSNumber numberWithInt:CDCServerPortValue]
forKey:CDCServerPort];
[defaultValues setObject:[NSNumber
numberWithBool:CDCServerLaunchValue] forKey:CDCServerLaunch];
NSLog( [defaultValues description] );
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
}
/**
* Constructor
* @return id Pointer to created instance
*/
-(id)init
{
self = [super init];
if( self )
{
//load all
NSLog(@"load all");
NSLog( [[NSUserDefaults standardUserDefaults] description] );
m_strClientIp = [[NSUserDefaults standardUserDefaults]
objectForKey:CDCClientIp];
m_iClientPort = [[NSUserDefaults standardUserDefaults]
integerForKey:CDCClientPort];
m_fRegisterProtocol = [[NSUserDefaults standardUserDefaults]
boolForKey:CDCClientRegister];
m_strServerIp = [[NSUserDefaults standardUserDefaults]
objectForKey:CDCServerIp];
m_iServerPort = [[NSUserDefaults standardUserDefaults]
integerForKey:CDCServerPort];
m_fLaunchServer = [[NSUserDefaults standardUserDefaults]
boolForKey:CDCServerLaunch];
//init
m_oProtocol = [[ed2kProtocol alloc] init];
m_oServer = [[ed2kServer alloc] init];
//setup client and server
[self registerProtocol:nil ];
[self launchServer:nil ];
}
return self;
}
/**
* Destructor which is called when the reference count of our object
reaches zero
* @bug not fired
*/
-(void)dealloc
{
//save all
NSLog(@"save all");
[[NSUserDefaults standardUserDefaults] setObject:m_strClientIp
forKey:CDCClientIp];
[[NSUserDefaults standardUserDefaults] setInteger:m_iClientPort
forKey:CDCClientPort];
[[NSUserDefaults standardUserDefaults] setBool:m_fRegisterProtocol
forKey:CDCClientRegister];
[[NSUserDefaults standardUserDefaults] setObject:m_strServerIp
forKey:CDCServerIp];
[[NSUserDefaults standardUserDefaults] setInteger:m_iServerPort
forKey:CDCServerPort];
[[NSUserDefaults standardUserDefaults] setBool:m_fRegisterProtocol
forKey:CDCServerLaunch];
[m_oItem release];
[m_oProtocol release];
[m_oServer release];
[super dealloc];
}
/**
* Called when loaded from nib and all outlets are set
*/
- (void)awakeFromNib
{
m_oItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength] retain];
//in conjunction with image use NSSquareStatusItemLength
//[m_oItem setHasShadow:NO]; //not working!? -> warning
[m_oItem setHighlightMode:NO];
[m_oItem setTitle:@"ed2k"]; //set an image instead
[m_oItem setMenu:menuReference];
[m_oItem setEnabled:YES];
}
/**
* Called after the window is loaded to initialize our GUI
* @bug not fired
*/
-(void)windowDidLoad
{
//set the UI components
NSLog( @"set the UI components" );
[ipClientField setStringValue:m_strClientIp];
[portClientField setIntValue:m_iClientPort];
[registerButton setState: (m_fRegisterProtocol) ? NSOnState :
NSOffState];
[ipServerField setStringValue:m_strServerIp];
[portServerField setIntValue:m_iServerPort];
[launchButton setState: (m_fLaunchServer) ? NSOnState : NSOffState];
}
/**
* Registers our ed2k:// protocol with user-defined ip and port -
called from GUI or from code in which case there is no sender
* @param sender id a GUI object or nil when called from code
*/
- (IBAction)registerProtocol:(id)sender
{
NSLog(@"register protocol");
//check if there is a sender
if( sender != nil )
{
//read GUI
m_strClientIp = [ipClientField stringValue];
m_iClientPort = [portClientField intValue];
m_fRegisterProtocol = ([sender state] == NSOnState) ? YES : NO;
}
//register/unregister
if( m_fRegisterProtocol )
[m_oProtocol registerProtocolForIp: m_strClientIp atPort:
m_iClientPort];
else
[m_oProtocol unregisterProtocol];
}
/**
* Launches our server with user-defined ip and port - called from GUI
or from code in which case there is no sender
* @param sender id a GUI object or nil when called from code
*/
- (IBAction)launchServer:(id)sender
{
NSLog(@"launch server");
if( sender )
{
//read GUI
m_strServerIp = [ipServerField stringValue];
m_iServerPort = [portServerField intValue];
m_fLaunchServer = ([sender state] == NSOnState) ? YES : NO;
}
//launch/shutdown
if( m_fLaunchServer )
[m_oServer launchServerAtIp: m_strServerIp onPort: m_iServerPort];
else
[m_oServer shutdownServer];
}
/**
* Shows the console tab of our window
* @param sender id a GUI object
*/
- (IBAction)showConsole:(id)sender
{
NSLog(@"opening console");
[self showTabAtIndex:0];
}
/**
* Shows the client tab of our window
* @param sender id a GUI object
*/
- (IBAction)showClientPreferences:(id)sender
{
NSLog(@"opening client prefs");
[self showTabAtIndex:1];
}
/**
* Shows the server tab of our window
* @param sender id a GUI object
*/
- (IBAction)showServerPreferences:(id)sender
{
NSLog(@"opening server prefs");
[self showTabAtIndex:2];
}
/**
* Shows the the specified tab of our window
* @param index int The tab to activate
*/
- (void)showTabAtIndex:(int)index
{
[self showWindow:self];
//activate tab
[tabField selectTabViewItemAtIndex:index];
}
@end
</code>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.