我正在对在iOS应用中的文本字段中输入的NSString值进行编码。
这是我的代码
NSString *encodedStrr = [myTextFeild.text encodeString:NSUTF8StringEncoding];
NSString *encodedUrlStrr = [NSString stringWithFormat:
@"http://www.damain.com:8080/app/f/query?from=%@",
encodedStrr];
NSURL *urlr11 = [NSURL URLWithString: encodedUrlStrr];
我收到以下错误,
2016-04-19 11:45:46.186 FactualNote[3137:11303] -[__NSCFString encodeString:]: unrecognized selector sent to instance 0x71c5100
2016-04-19 11:45:46.187 FactualNote[3137:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [__NSCFString encodeString:]: unrecognized selector sent to instance 0x71c5100'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1e4bd 0x1c82bbc 0x1c8294e 0x30ff 0x10e4705 0x182c0 0x18258 0xd9021 0xd957f 0xd86e8 0x47cef 0x47f02 0x25d4a 0x17698 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x14ffc 0x1eed 0x1e15)
libc ++ abi.dylib:终止调用抛出异常
我按照此网址编码https://madebymany.com/blog/url-encoding-an-nsstring-on-ios。
这是我正在使用的文件,并在viewController.m中导入。
Desing.h
@interface NSString (encode)
- (NSString *)encodeString:(NSStringEncoding)encoding;
@end
Desing.m
@implementation NSString (encode)
- (NSString *)encodeString:(NSStringEncoding)encoding
{
return (NSString *) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self,
NULL, (CFStringRef)@";/?:@&=$+{}<>,",
CFStringConvertNSStringEncodingToEncoding(encoding)));
}
@end
以下帖子回答说,这可能是内存问题Unrecognized Selector Sent to Instance [NSCFString subarrayWithRange:]。
我如何从这里出来。
答案 0 :(得分:0)
检查您的类别(Desing.m)是否已添加到目标中,这可能是原因。