原因和解决方案如何 - [__ NSCFConstantString trim]?

时间:2013-06-01 07:21:26

标签: objective-c

我使用j2objc。 从java到objective-c(ios)

2013-06-01 16:17:10.770 tttttt[4433:907] -[__NSCFConstantString trim]: unrecognized selector sent to instance 0x2aba60
2013-06-01 16:17:10.774 tttttt[4433:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString trim]: unrecognized selector sent to instance 0x2aba60'
*** First throw call stack:
(0x311d93e7 0x38ed4963 0x311dcf31 0x311db64d 0x31133208 0x114d2d 0x124625 0x151329 0x150905 0x150e3b 0x1505e3 0xfbe53 0x330d3087 0x330d303b 0x330d3015 0x330d28cb 0x330d2db9 0x32ffb5f9 0x32fe88e1 0x32fe81ef 0x34d005f7 0x34d00227 0x311ae3e7 0x311ae38b 0x311ad20f 0x3112023d 0x311200c9 0x34cff33b 0x3303c2b9 0xfb71f 0x39301b20)
libc++abi.dylib: terminate called throwing an exception

请告诉我原因和解决方案

2 个答案:

答案 0 :(得分:3)

原因是缺少方法[NSString trim]。请参阅NSString Class Reference

答案 1 :(得分:1)

你想修剪NSSString,这是不可能的。甚至没有修剪方法。无论如何,字符串是不可变的对象。

所以你想要一个新的字符串

NSString *b = [a stringByTrimming...];

或者你制作一个可变副本并修剪

NSMutableString *b = [a mutableCopy];
[b trim...];
....
[b release]; //if you don't use ARC, you need to release b