I have a UITableView that was created from data coming from a mutable array.
This is an array of dictionaries. So, in order to populate my table, I did something like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
NSDictionary *umObject = (NSDictionary*)[listaDeObjectos objectAtIndex:indexPath.row];
NSString *oneName = [umObject objectForKey:@"name"];
[cell setText:oneName];
...
}
This is working fine, but now I am trying to implement a search on this table. I read a tutorial where the guy uses a search method like this...
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[searchedData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:@""] || searchText==nil){
[myTableView reloadData];
searching = NO;
return;
}
searching = YES;
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText];
if(r.location != NSNotFound)
[searchedData addObject:name];
counter++;
[pool release];
}
[myTableView reloadData];
}
as you can see, he has this line
for(NSString *name in dataSource)
where name is an entry from dataSource (??)
This sounds like the table being populated from some kind of array, but, as far as I know, my table was not populated from an array directly, but instead, from values I extracted on the first part of my code, one by one.
I am not sure if I understood the concept of datasource.
I have read the docs but I am still not understanding that.
What is this datasource? Does my table has one? If not, how do I search my table?
Cay you guys help?
thanks