从NSTextField获取文本并将其设置为已定义的String [英] Getting the text from a NSTextField and setting it to an already defined String

查看:210
本文介绍了从NSTextField获取文本并将其设置为已定义的String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是可可的新手,我一直在努力寻找答案并找出答案.

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

如果我有一个NSTextField,如何获取该值(字符串值)并将其保存在预定义的字符串变量中,然后在使用NSLog()的调试中将其显示出来?

if I have a NSTextField how can I get the value (stringvalue) of that and save it in a predefined string variable, there after display it in the debug using NSLog()?

谢谢

推荐答案

只需使用NSTextField的stringValue方法并将其保存到NSString

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

只需将displayString方法连接到NSTextField,它就可以工作.

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

这篇关于从NSTextField获取文本并将其设置为已定义的String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆