[英]How to get value of NSTextField dynamic add to NSMutableArray?
[英]How can I get the value inside of an NSTextField?
我的NSTextField包含諸如“ 1.67”或“ 0.05”等的雙打。
當我嘗試以下操作時:
console.log([priceChange doubleValue]); //priceChange is an NSTextField
//Apply styles
if([priceChange doubleValue] > 0)
[priceChange setTextColor:[NSColor greenColor]];
else if([priceChange doubleValue] < 0)
[priceChange setTextColor:[NSColor redColor]];
else if([priceChange doubleValue] == 0)
[priceChange setTextColor:[NSColor blackColor]];
priceChange始終等於0,即使該值是其他值也是如此。 如何正確獲得priceChange的值?
嘗試[[priceChange stringValue] floatValue]
。 另外,請確保字符串中的數字之前沒有空格,否則,floatValue將返回0。
這正是NSNumberFormatter
的用途。 給您的字段一個合適的格式化程序(易於在IB中添加/設置),並且-objectValue將開始返回NSNumber
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.