problem in searching table views
<p>I am facing a problem in implementing the search functionality in Table Views... Here is the code i am implementing to search...</p>

<pre><code>- (void) searchTableView {

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

searchArray = [data boats];

for(Boat *boat in searchArray)
{
    NSRange titleResultsRange = [[boat boatName] rangeOfString:searchText options:NSCaseInsensitiveSearch];

    if (titleResultsRange.length &gt; 0)
        [copyListOfItems addObject:boat];
}

[searchArray release];
searchArray = nil;
</code></pre>

<p>}</p>

<p>When the search bar starts getting edited, i call this...</p>

<pre><code>- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {

//Remove all objects first.
[copyListOfItems removeAllObjects];

if([searchText length] &gt; 0) {

    [ovController.view removeFromSuperview];
    searching = YES;
    letUserSelectRow = YES;
    self.tableView.scrollEnabled = YES;
    [self searchTableView];
}
else {

    [self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];

    searching = NO;
    letUserSelectRow = NO;
    self.tableView.scrollEnabled = NO;
}

[self.tableView reloadData];
</code></pre>

<p>}</p>

<p>and i assign the value to table row using...</p>

<pre><code>if(searching)
{
    Boat *copyboat = [copyListOfItems objectAtIndex:[indexPath row]];
    cell.textLabel.text = [copyboat boatName];
    NSLog(@"%@", [copyboat boatName]);
}
else {
    Boat *fullboat =[data.boats objectAtIndex:[indexPath row]];
    cell.textLabel.text =[fullboat boatName];       
}
</code></pre>

<p>But when i start typing the values in search bar, the app is crashing. I get different errors when i type different alphabets. I get errors like.
<strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[NSMutableArray objectAtIndex:]: index 6 beyond bounds [0 .. 5]'</p>

<p>or </p>

<p><strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '*</strong> -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'</p>

<p>Sometime its also showing EXEC_BAD_ACCESS also... I am screwed right now. Can anyone please tell me what the error exactly is...???</p>
