views:

154

answers:

2

Hi Guys

I created a nib file and want to display dynamic text messages on it like file names that are selected or the no of files selected etc. Is there a way to to this?

I know this can be done for alert panels but i want it on my custom sheets.

Thanks

+3  A: 

Either create connections between your NSTextField elements and your controller class and then set the labels programmatically (using setStringValue).

Or you could consider using bindings. See http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html.

Chris Suter
Thanks Chris. I think i will use setStringValue method.
King
+1  A: 

You can create a NSTextField programmatically like this:

(IBAction)showText:(id)sender {
    NSRect frame = NSMakeRect(50, 50, 200, 100);
    NSTextField *tf = [[NSTextField alloc] initWithFrame:frame];
    [tf setStringValue:@"test"];
    [tf setSelectable:NO];
    [tf setEditable:NO];
    [tf setBordered:NO];
    [tf setDrawsBackground:NO];
    [[[sender window] contentView] addSubview:tf];
    [tf release];
}

or you could use NSString's methods for drawing text in a view, namely -drawAtPoint or -drawInRect

Woofy
Thanks Woofy. I think i will use the above method.
King