我有一个UITableView是根据来自可变数组的数据创建的。这是字典数组。因此,为了填充我的表,我不喜欢的东西iPhone - UITableView数据源?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
NSDictionary *umObject = (NSDictionary*)[listaDeObjectos objectAtIndex:indexPath.row];
NSString *oneName = [umObject objectForKey:@"name"];
[cell setText:oneName];
...
}
这是工作正常,但现在我想实现在此表上的搜索。我看了其中的人使用这样的搜索方法教程...
- (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];
}
,你可以看到,他此行
for(NSString *name in dataSource)
其中名称是从数据源中的条目(??)
这听起来像是从某种数组中填充表,但据我所知,我的表没有直接从数组填充,而是从我在代码的第一部分提取的值,逐个。
我不确定是否理解了数据源的概念。
我已阅读文档,但我仍然不理解。
这是什么数据源?我的桌子有一个吗?如果没有,我该如何搜索我的桌子?
礁你们帮忙吗?
感谢
谢谢!!!!!!!!! – SpaceDog 2010-06-23 02:50:03