从textField获取int

Tom*_*oda 5 macos cocoa objective-c

我是可可的新手.我创建项目,我有一个textField和一个按钮.我为按钮创建功能,我开始其他功能,没关系.但我需要从textField获取数值作为我的函数的参数...像这样:

@implementation AppController

- (IBAction)StartReconstruction:(id)sender {
    int RecLine = //here i need something like textField1.GetIntValue();
    drawGL(RecLine);
}
@end
Run Code Online (Sandbox Code Playgroud)

在IB中我只创建数字格式文本字段.但我不知道如何从代码中调用它:(

感谢帮助

rfo*_*rte 0

您应该能够执行以下操作:


int RecLine = [textField1.text intValue];
Run Code Online (Sandbox Code Playgroud)

这是假设您的 textField1 有可以转换为整数的内容。

  • “textField1.text”适用于 UITextField,但不适用于 NSTextField。除非我弄错了,否则我认为这是一个 Cocoa 问题,而不是 Cocoa Touch 问题。 (2认同)