Tar*_*rma 5 iphone objective-c nsstring ios7
我需要检查String是否包含特定字符串.为此,我使用的是NSString类的函数,名为c containssstring.这个函数在ios8中工作正常而不会抛出任何异常,但是在ios7的情况下它会抛出一个异常调用
unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
我使用了try&catch块来防止异常,但我可能知道为什么会这样吗?
提前致谢
Esh*_*sha 14
您可以签入框架标题.

- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);
Run Code Online (Sandbox Code Playgroud)
这个containsString方法只存在于iOS 8之后,所以很明显它会在iOS7中抛出错误....
请使用以下ios7的方法,你可以使用上面的方法为ios8:
if ([string rangeOfString:@"bla"].location != NSNotFound)
{
NSLog(@"charecter found");
}
Run Code Online (Sandbox Code Playgroud)
可能这可以解决您的问题.谢谢
| 归档时间: |
|
| 查看次数: |
2808 次 |
| 最近记录: |