开发者

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

开发者 https://www.devze.com 2023-04-08 07:05 出处:网络
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, 开发者

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

精彩评论

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