开发者

Getting the text from a NSTextField and setting it to an already defined String

Im brand new to Cocoa, and im struggling to find the answer and figure it out.

if I have a NSTextField how can I get the value (stringvalue) of that and save it in a predefined string variable, 开发者_如何学Gothere after display it in the debug using NSLog()?

Thanks


Just use the stringValue method by NSTextField and save it to a NSString



@interface MyClass : NSObject
{
    NSTextField *textField;
}
-(IBAction)displayString:(id)sender;
@end


@implementation

-(IBAction)displayString:(id)sender
{
    NSString *string = [textField stringValue];
    NSLog (@"%@", string);
}

@end

Just connect the displayString method to the NSTextField and it should work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜