views:

25

answers:

1

Hello,

I am trying to create a simple framework with a nib that has a button on it which can be customized (selector wise and title wise.) for this, i did the following:

I added a property:

@property (nonatomic,retain) NSButton*accessoryButton;

and connected it to my outlet:

@synthesize accessoryButton = littleButton;

I then shared the instance as such:

+ (TestWindow *)sharedPanel
{
    return sharedPanel ? sharedPanel : [[[self alloc] init] autorelease];
}

- (id)init 
{
    if (sharedPanel) {
        [self dealloc];
    } else {
        sharedPanel = [super init];
    }

    return sharedPanel;
}

and load the nib:

 if( !somewindow ) 
 {
  [NSBundle loadNibNamed: @"window" owner:nil];
 }
 [NSApp activateIgnoringOtherApps:YES];
 [somewindow center];
 [somewindow setLevel:NSModalPanelWindowLevel];
 [somewindow makeKeyAndOrderFront:self];

When I however want to change the title for example from my sample project, it never works.

[TestWindow sharedPanel] setTitle:@"hi"]; //doesnt work

Here's my setTitle: method:

-(void)setTitle:(NSString *)buttonTitle
{
 [[self accessoryButton] setTitle:buttonTitle];
 [[self accessoryButton] display];
}

I don't get an error but nothing happens either. What am I missing?

A: 

Is the button nil at runtime? Are you sure your button's outlet is connected?

Joshua Nozzi
I've tested again, the button does not return nil. `-(void)setTitle:(NSString *)buttonTitle{ if (self.accessoryButton == nil) { NSLog(@"Button is nil"); } [[self accessoryButton] setTitle:buttonTitle]; [[self accessoryButton] display];}`
David Schiefer