可可应用程序中NSSTring和NSTextField数据的奇怪问题 [英] Strange issue with NSSTring and NSTextField data in cocoa app
问题描述
我有一个非常基本的可可osx应用程序,它有一个文本字段和一个按钮。
当您在文本框中键入内容并单击按钮时只需在文本框中设置一个带有值的变量 -
- (IBAction)getText:(NSButton *)sender {
NSString * textFromField = _theText.stringValue;
}
如果我在文本框中键入少于7个字符,则变量设置正确。
如果我在文本框中输入7到11个字符,那么变量最后会有垃圾。
这是All Output窗口的副本 -
(lldb)print textFromField
(NSString *)$ 0 = 0x000000010241c060 @12345
(lldb)print textFromField
(NSString *)$ 1 = 0x0000000102425260 @1234567 \ xd0 \ xc4h $ \ x10
(lldb)print textFromField
( NSString *)$ 2 = 0x0000000100510a30 @123456789.\x05 \ x10
(lldb)print textFromField
(NSString *)$ 3 = 0x00000001022370d0 @123456789012
(lldb)
你可以看到,如果我在文本框中键入12345,变量显示12345
但是如果我键入1234567,变量显示1234567 \xd0 \ xc4h $ \ x10
它显示额外的垃圾直到你起床12个字符然后又好了。
任何想法为什么会发生这种情况?
I have a very basic cocoa osx app that has a text field and a button.
When you type something in to the text box and click the button it just sets a variable with the value in the text box -
- (IBAction)getText:(NSButton *)sender {
NSString *textFromField = _theText.stringValue;
}
If I type less then 7 characters in to the text box the variable gets set correctly.
If I type 7 to 11 characters in the text box the variable has garbage at the end.
Here is a copy of the All Output window -
(lldb) print textFromField
(NSString *) $0 = 0x000000010241c060 @"12345"
(lldb) print textFromField
(NSString *) $1 = 0x0000000102425260 @"1234567\xd0\xc4h$\x10"
(lldb) print textFromField
(NSString *) $2 = 0x0000000100510a30 @"123456789.\x05\x10"
(lldb) print textFromField
(NSString *) $3 = 0x00000001022370d0 @"123456789012"
(lldb)
You can see that if I type 12345 in to the text box, the variable shows 12345
But if I type 1234567 the variable shows 1234567\xd0\xc4h$\x10
It shows the extra garbage until you get up to 12 characters then it is fine again.
Any ideas why this happens?
推荐答案
0 = 0x000000010241c060 @12345
(lldb)print textFromField
(NSString *)
0 = 0x000000010241c060 @"12345"
(lldb) print textFromField
(NSString *)
1 = 0x0000000102425260 @1234567 \ xd0 \\ \\ xc4h
1 = 0x0000000102425260 @"1234567\xd0\xc4h
\ x10
(lldb)print textFromField
(NSString *)
\x10"
(lldb) print textFromField
(NSString *)
这篇关于可可应用程序中NSSTring和NSTextField数据的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!