单击键盘上的任何值时出错

发布于 2024-11-15 06:44:03 字数 964 浏览 4 评论 0原文

大家好,

当我单击键盘上的任何值时,我不断收到此错误...我可以运行我的代码,但当我想做搜索时收到此错误...

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM rangeOfString:options:]: unrecognized selector sent to instance 0x4e2a830'
*** Call stack at first throw:

请在这里帮助这个菜鸟..我已经智穷了... =(

- (void) searchTableView {

    NSString *searchText = searchBar.text;
    NSMutableArray *searchArray = [[NSMutableArray alloc] init];

    for (NSDictionary *patients in listOfItems)
    {
         NSArray *array = [patients objectForKey:@"Patients"];
        [searchArray addObjectsFromArray:array];
    }

    for (NSString *sTemp in searchArray)
    {
        NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length != 0)
            [copyListOfItems addObject:sTemp];
    }

    [searchArray release];
    searchArray = nil;
}

Hi any kind souls out there,

I keep getting this error when i am click any value on the keyboard... I can run my codes but get this error when i want to do a search...

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM rangeOfString:options:]: unrecognized selector sent to instance 0x4e2a830'
*** Call stack at first throw:

Please help this noob here.. I am at end wits... =(

- (void) searchTableView {

    NSString *searchText = searchBar.text;
    NSMutableArray *searchArray = [[NSMutableArray alloc] init];

    for (NSDictionary *patients in listOfItems)
    {
         NSArray *array = [patients objectForKey:@"Patients"];
        [searchArray addObjectsFromArray:array];
    }

    for (NSString *sTemp in searchArray)
    {
        NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if (titleResultsRange.length != 0)
            [copyListOfItems addObject:sTemp];
    }

    [searchArray release];
    searchArray = nil;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一百个冬季 2024-11-22 06:44:03

搜索数组中的对象是 NSArray 对象,这意味着它们不会响应选择器 rangeOfString:,因为这是一个 NSString 方法

for (NSString *sTemp in searchArray) 
{ 
   NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
   if (titleResultsRange.length != 0)
     [copyListOfItems addObject:sTemp];
}

应该是这样的:

for(NSArray *array in searchArray)
{
   // NSString *str = [array objectAtIndex:0];
    PatientInfoObject *obj = [array objectAtIndex:0];
    NSString *str = obj.id;
    // to be sure
    if( [str isKindOfClass:[NSString class]] )
    {
       NSRange titleResultsRange = [str rangeOfString:searchText options:NSCaseInsensitiveCompare];
       if( titleResultsRange.length != 0 )
       {
         [copyListOfItems addObject:str];
       }
    }
    else
    {
        // this shouldn't have happened, log something to console
        NSLog(@"**Object in array is not of type NSString**");
     }
}

The objects in your search array are NSArray objects, this means that they do not respond to the selector rangeOfString: as that is a NSString method

for (NSString *sTemp in searchArray) 
{ 
   NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
   if (titleResultsRange.length != 0)
     [copyListOfItems addObject:sTemp];
}

should be something like:

for(NSArray *array in searchArray)
{
   // NSString *str = [array objectAtIndex:0];
    PatientInfoObject *obj = [array objectAtIndex:0];
    NSString *str = obj.id;
    // to be sure
    if( [str isKindOfClass:[NSString class]] )
    {
       NSRange titleResultsRange = [str rangeOfString:searchText options:NSCaseInsensitiveCompare];
       if( titleResultsRange.length != 0 )
       {
         [copyListOfItems addObject:str];
       }
    }
    else
    {
        // this shouldn't have happened, log something to console
        NSLog(@"**Object in array is not of type NSString**");
     }
}
鹤舞 2024-11-22 06:44:03

您正在 searchArray 中添加数组对象。

你的应用程序在这里崩溃 NSString *sTemp in searchArray 因为 sTemp 包含 NSArray 对象而不是 NSString 对象。

You are adding array object in your searchArray.

your app is getting crash NSString *sTemp in searchArray here because sTemp contains NSArray object not NSString object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文