2011-02-11 22 views
1

我有在執行以下代碼中的問題,而在表中搜索。這段代碼在別處工作正常。但是目前我們正在給一個錯誤[_UITableViewSeparatorView rangeOfString:]:無法識別的選擇發送到實例

[_UITableViewSeparatorView rangeOfString:]:無法識別的選擇發送到實例0x6041790

以下是困擾我的代碼。請讓我知道在那裏隱藏的bug。

- (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]; } 

在此先感謝!

期待您的回覆。

謝謝

回答

1

它看起來像你過度釋放您已存儲在數據源中的字符串。我會檢查你使用/創建這些字符串的任何地方,以確保你沒有多次釋放它們。

+0

感謝一噸!.....我沒有注意到的是,雖然編碼.. ...錯我選擇了它,同時初始化 – devsri

0

你在投入什麼dataSource?顯然,它包含一個不是NSString的對象。

1

這意味着,如果該字符串應該駐留在內存內存被釋放了,並沒有對那個地方(在你的情況_UITableViewSeparatorView)的另一個對象。請確保您沒有過度釋放的陣列

您可以嘗試在文書NSZombiesEnabled搜索的字符串:link

+0

感謝一噸可以自動釋放!.....我沒有注意到的是,雖然編碼.....錯我選擇了它,而BTW初始化 – devsri

+0

不能自動釋放接受多個答案在這裏......但是,謝謝你的幫助救了我的一天!! .... :) – devsri

+1

你可以投票了;) – Max

相關問題