开发者

Accessing Button in NIB that is in my framework

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"]; //开发者_如何学Pythondoesnt 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?


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


Does your init function get called when the NIB is loaded?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜