首页 > 代码库 > __NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160
__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160
If you want your code to work on iOS 7 as well as iOS 8 you should use one of the rangeOfString calls instead. Basically if the range returned has a length of zero, the substring is not there.
/* These methods return length==0 if the target string is not found. So, to check for containment: ([str rangeOfString:@"target"].length > 0). Note that the length of the range returned by these methods might be different than the length of the target string, due composed characters and such. */ - (NSRange)rangeOfString:(NSString *)aString; - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask; - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)searchRange; - (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)searchRange locale:(NSLocale
@implementation NSString (Contains) - (BOOL)myContainsString:(NSString*)other { NSRange range = [self rangeOfString:other]; return range.length != 0; } @end
原文链接
http://stackoverflow.com/questions/26410420/nsstring-containsstring-crashes
__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。