objective-c - 如何从 NSTextField 设置静态 int
问题描述
我无法从 UI NSTextField 设置静态 int。如果我在下面显示的代码片段中手动设置我的静态值:
int startVal = [startingTextField intValue];
static int theIndex = 1;
它当然不会产生错误。但是,如果我尝试从 textField 中获取的 int 设置静态(如我所愿),如下所示:
int startVal = [startingTextField intValue];
static int theIndex = startVal;
我在第二个(静态)行上得到一个令人惊讶的“初始化器元素不是编译时常量”错误。是什么原因造成的,正确的语法是什么?
解决方案
该消息解释了它。如果将其设置为 1,则编译器可以这样做,因为它在编译时是已知的。您将不得不以不同的方式进行操作,例如
static int theIndex = 1;
然后当你知道价值时,以某种方式
theIndex = [startingTextField intValue];
问题在于初始化,而不是分配。
推荐阅读
- swift - SDKApplicationDelegate 使用未解析的标识符
- cookies - 正确(技术上)处理 cookie 同意
- excel - 选择工作表命令在损坏的 Excel 文件中不起作用
- ios - 如何使用 com.whatsapp 或 com.facebook.Facebook 等捆绑标识符打开外部应用程序?
- java - 在枚举中调用超类型构造函数之前无法引用 Const.getText
- vb.net - 当用户没有在多行文本框的第二行输入文本时,如何添加错误消息?
- sql - 我不知道 SELECT for NAME, SURNAME, AGE, OS_NAME where age> = 15 之后会发生什么
- kernel - media-ctl IPU 绑定:无法设置链接
- momentjs - 如何使用时刻从两个日期范围获得星期五到星期五的星期
- c# - WindowStartupLocation CenterOwner is only working in Visual Studio