[_UITableViewSeparatorView rangeOfString:]:发送到实例的无法识别的选择器

时间:2011-02-11 05:09:42

标签: iphone objective-c xcode memory-management runtime-error

我在搜索表时执行以下代码时遇到问题。此代码在其他地方工作正常但目前正在给出错误

  

[_ UITableViewSeparatorView rangeOfString:]:无法识别的选择器发送到实例0x6041790

以下代码令我不安。请让我知道那里的错误。

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  {
       [tableData removeAllObjects];// remove all data that belongs to previous search
       if([searchText isEqualToString:@""] || searchText==nil)
       {
            [displayTable reloadData];
            return;
       }
    NSInteger counter = 0;
       for(NSString *name in dataSource)
    {
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
            NSRange r = [name rangeOfString:searchText];
            if(r.location != NSNotFound)
            {
                if(r.location== 0)//that is we are checking only the start of the names.
                {
                    [tableData addObject:name];
                }
            }
            counter++;
            [pool release];
        }

    [displayTable reloadData];    }

提前致谢!!

期待您的回复。

感谢

3 个答案:

答案 0 :(得分:1)

看起来你过度释放了存储在dataSource中的字符串。我会检查你使用/创建这些字符串的任何地方,以确保你没有发布它们的次数超过你应该。

答案 1 :(得分:1)

这意味着字符串应该驻留在内存中的内存被释放,并且该位置还有另一个对象(在您的情况下为_UITableViewSeparatorView)。确保您没有过度释放数组中的字符串

您可以尝试在乐器中搜索NSZombiesEnabled:link

答案 2 :(得分:0)

你在dataSource放了什么?显然,它包含一个不是NSString的对象。