将NSStepper与NSTextField集成 [英] Integrate NSStepper with NSTextField

查看:163
本文介绍了将NSStepper与NSTextField集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有一个与NSStepper一起使用的NSTextField作为一个控件,以便我可以通过直接在文本字段上更改整数值或使用步进器上/下箭头来编辑整数值。

I need to have a NSTextField working with a NSStepper as being one control so that I can edit an integer value either by changing it directly on the text field or using the stepper up/down arrows.

在IB中,我添加了这两个控件,然后将NSStepper的takeIntValueFrom连接到NSTextField,每当我单击步进箭头时,文本值都会更改。问题是,如果我编辑文本字段然后再次单击步进器,它将忘记我手动编辑的值并使用步进器的内部值。

In IB I've added both of these controls then connected NSStepper's takeIntValueFrom to NSTextField and that makes the text value to change whenever I click the stepper arrows. Problem is that if I edit the text field then click the stepper again it will forget about the value I manually edited and use the stepper's internal value.

什么是最好/最简单的文本字段值更改时,如何更新步进值?

What's the best/easiest way to have the stepper's value be updated whenever the text field value is changed?

推荐答案

跳过 takeIntValueFrom:方法。而是将两个视图绑定到控制器中的相同属性。您可能还需要创建一个格式化程序,并将文本字段的 formatter 出口连接到它。

Skip the takeIntValueFrom: method. Instead, bind both views to the same property in your controller. You may also want to create a formatter and hook up the text field's formatter outlet to it.

这篇关于将NSStepper与NSTextField集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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