【问题标题】:'NSInvalidArgumentException', reason: '-[__NSCFString encodeString:]: unrecognized selector sent to instance'NSInvalidArgumentException',原因:'-[__NSCFString encodeString:]:无法识别的选择器发送到实例
【发布时间】:2016-04-20 06:32:54
【问题描述】:

我正在对在 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。

设计.h

@interface NSString (encode)
    - (NSString *)encodeString:(NSStringEncoding)encoding;
@end

设计.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:]

我该如何摆脱困境。

【问题讨论】:

  • 添加了更多细节,请看一下
  • 文本中的哪个文本提交了此崩溃或每个文本?由于代码看起来不错,可能是文本字段的问题
  • 我的 textfeild 值是关于错误的 'zeptoh.com/lynked/sel.html',我在控制台上更新了我的问题,显示完全错误。
  • 这不是实际代码。异常抱怨 encodeString1
  • 不是的,其实我是改了测试改名的,其实说的是encodeString而已。

标签: ios objective-c


【解决方案1】:

检查您的类别 (Desing.m) 是否已添加到您的目标中,这可能是原因。

【讨论】:

  • 是的,它在构建阶段可用 - 编译源代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多