2011-01-19 78 views
-2

我有这样的记录。如何实现搜索Objective-c?

名字 - 姓氏 - PHONENO - 地址 - 名称

  1. A - 米克 - 789367789 - 纽约 - 教授

  2. 乙 - Jossef - 534647458 - 美国 - 医生

  3. Ç - 沙 - 342576765 - 美国 - 医生

  4. d - 吉 - 535346457 - 美国 - 商人

......正如这个

我在UITableView中显示一个名字用的UISearchBar。搜索正在根据数据的关键字在搜索栏的打字声,而是假设您键入M感受列举M,然后后,当我点击M的第一个项目中的所有项目精细它过滤,它会显示一个而不是M的详细信息在下一个视图。

我想你能明白我的问题。

我该如何解决如何在相应记录下一个视图传递多个值?

谢谢,

此功能从我的TableView中相同的代码(与搜索栏苹果示例代码)了。 和我根据我的逻辑修改此。

- (void) searchTableView 
{ 

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

    NSInteger TotalNoOfRecords=[self.SearchtableDataSource count]; 
    for (int i=0;i<TotalNoOfRecords;i++) 
    { NSDictionary *dictionary = [self.SearchtableDataSource objectAtIndex:i]; 
     NSArray *array = [dictionary objectForKey:@"Title"]; 
     NSString *arrayID= [dictionary objectForKey:@"ID"]; 
     NSLog(@"Testing - Id-%d",arrayID); 
     [searchArrayID addObject:arrayID]; 
     [searchArray addObject:array]; 
    } 

    for (NSString *sTemp in searchArray) 
    { 

     NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch]; 

     if (titleResultsRange.length > 0) 
     { 
       [copyListOfItems addObject:sTemp]; 
     } 
    } 

    [searchArray release]; 
    searchArray = nil; 
} 

这是我didSelectRowAtIndexPath代码我知道这需要修改,但我不知道如何?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *dictionary = [self.SearchtableDataSource objectAtIndex:indexPath.row]; 
    FirstName= [dictionary objectForKey:@"FirstName"]; 
    LastName=[dictionary objectForKey:@"LastName"]; 
    DetailViewController *ivc = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];  
    ivc.FirstName = FirstName; 
    ivc.LastName=LastName; 
    ivc.Title=[dictionary objectForKey:@"Details of Person"]; 
    [self.navigationController pushViewController:ivc animated:YES];  
    [ivc release]; 
} 

请帮我...

感谢

+0

编辑你的问题和一些代码,然后我们会帮你。 – Tirth 2011-01-19 04:37:57

+0

post didSelectRowAtIndexPath代码 – KingofBliss 2011-01-19 04:54:35

回答

0

检查你是从copyListOfItems-didSelectRowAtIndexPath检索值。

编辑:

你应该清楚先了解逻辑。 SearchedTableDatasource包含tableViews在tableview中加载的完整数据集。 copyListofItems包含过滤的项目。因此,在didSelectRowAtIndexPath方法,你应该代码如下所示,

if(searching==YES) 

{ 

//retrieve the values from copyListofItems array 

} 

else 

{ 

//retrieve the values from SearchedTableDatasource array 

} 

,你也正在使用搜索的空函数,如果是这样声明copyListofItems数组作为全球性的,要么做回一个NSMutableArray的实例的功能。

0

更改didSelectRowAtIndexPath方法方法您init方法,并把字典对象并设置DetailViewController属性那里,我希望将工作,因为它为我工作。