简体   繁体   English

无法识别的选择器发送到iOS7中的实例异常

[英]unrecognized selector sent to instance exception in iOS7

I have a requirement to check whether a String contains a particular string or not.For that purpose i am using a function of NSString class called c containsstring . 我需要检查String是否包含特定字符串。为此,我使用的是NSString类的函数,名为c containssstring This function works fine in ios8 without throwing any kind of exception but in case of ios7 it is throwing an exception called 这个函数在ios8中工作正常而不会抛出任何异常,但是在ios7的情况下它会抛出一个异常调用

 unrecognized selector sent to instance 

I have used try & catch block to prevent the exception but may i know why this is happening? 我使用了try&catch块来防止异常,但我可能知道为什么会这样吗?

Thanks in advance 提前致谢

You can check in framework header. 您可以签入框架标题。 在此输入图像描述

- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);

This method of containsString only exist after iOS 8 so its obvious that it will throw error in iOS7.... 这个containsString方法只存在于iOS 8之后,所以很明显它会在iOS7中抛出错误....

Please use below method for ios7 and you can use above method for ios8: 请使用以下ios7的方法,你可以使用上面的方法为ios8:

if ([string rangeOfString:@"bla"].location != NSNotFound)
{
  NSLog(@"charecter found");
} 

May be this can solve your issue. 可能这可以解决您的问题。 Thanks 谢谢

Check if String retrieved from array is not nil . 检查从数组中检索的String是否为nil It will solve your problem. 它会解决你的问题。

Use following code it might resolve your issue. 使用以下代码可能会解决您的问题。

NSString *Test=arr_sub[0];
if(Test!=nil && [Test containsString:@"::"])
{
    NSlog(@"charecter found");
}

Let me know if you face any other isssue. 如果你遇到任何其他问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM