我已經實現了一個帶有兩個標籤的自定義單元格的TableView來填充城市名稱和城市ID(我保持城市ID標籤隱藏)。在這裏,我的問題是當我搜索城市名稱時,我也無法獲得城市ID,當我搜索城市名稱時,我希望這兩個值都被過濾。如何使用Obejctive C在tableview單元格中搜索特定值時獲取所有數組值?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"citylocation";
searchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (!cell) {
cell= [[searchTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
if(!isFilltered)
{
cell.textLabel.text = [avahotel objectAtIndex:indexPath.row];
cell.city.text = [[createdDate objectAtIndex:indexPath.row]stringValue];
}else
{
cell.textLabel.text = [filteredString objectAtIndex:indexPath.row];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(isFilltered)
{
return [filteredString count];
}
return [avahotel count];
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if(searchText.length == 0)
{
isFilltered = NO;
}else
{
isFilltered = YES;
filteredString = [[NSMutableArray alloc]init];
for(NSString *str in avahotel)
{
NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(stringRange.location != NSNotFound)
{
[filteredString addObject:str];
}
}
}
[_searchtableview reloadData];
}
我有一個問題在這裏。你想在filteredString數組中獲得關於城市ID的信息嗎?當真正搜索城市名稱?還是我誤解了? – Elena0987
搜索城市名稱和所有工作正常,我的需要是,如何過濾這兩個標籤。例如,如果我正在搜索欽奈的手段,我希望欽奈和城市id(100)值。 –