2013-12-20 59 views
1

我適應我的應用程序支持兩種iOS7和6原創的UITableView使用搜索欄

我使用了一個表視圖用於過濾的數據顯示一個搜索欄顯示在結果的UITableView。

但是,當我的搜索過濾,出現在原始數據表視圖之上的過濾數據的表視圖,因此它們重疊。

有沒有人有任何想法?

在此先感謝。

附上2張圖片:

  1. 沒有搜索。

enter image description here

  • 隨着搜索(你可以看到,表視圖重疊) enter image description here
  • 編輯:

    添加數據源方法

    #pragma mark - Table view data source 
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
    } 
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (tableView == self.searchDisplayController.searchResultsTableView) 
    { 
        return arregloFiltrado.count; 
    }else{ 
        return arreglo.count; 
    } 
    } 
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
        [[NSBundle mainBundle] loadNibNamed:@"CeldaLista" owner:self options:nil]; 
        cell = celdaLista; 
        self.celdaLista = nil; 
    } 
    
    
    if (tableView == self.searchDisplayController.searchResultsTableView) { 
        [(UILabel*)[cell viewWithTag:1] setText: /*Name and surname*/]; 
        [(UILabel*)[cell viewWithTag:2] setText: /*Other properties*/]; 
    
        if ([[arregloFiltrado objectAtIndex:indexPath.row] objectForKey:@"photo"] == nil) { 
         [(UIImageView*)[cell viewWithTag:4] setImage:/*No image*/]; 
        } 
        else{ 
         [(UIImageView*)[cell viewWithTag:4] setImage:/*Photo*/]; 
        } 
    } else { 
        [(UILabel*)[cell viewWithTag:1] setText:/*Name and surname*/]; 
        [(UILabel*)[cell viewWithTag:2] setText:/*Other properties*/]; 
    
        if ([[arreglo objectAtIndex:indexPath.row] objectForKey:@"photo"] == nil) { 
         [(UIImageView*)[cell viewWithTag:4] setImage:/*No image*/]; 
        } 
        else{ 
         [(UIImageView*)[cell viewWithTag:4] setImage:/*Photo*/]; 
        } 
    } 
    return cell; 
    } 
    

    還有更多?如果你使用它有它自己的UITabelview一個UISearchDisplayController

    - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView{ 
         tableView.backgroundColor = [UIColor whiteColor];//color of search result table 
        } 
    
    +0

    粘貼您的表視圖數據源代碼 –

    +0

    你使用兩個tableView嗎? –

    +0

    你可以請你出示你的代碼嗎? –

    回答

    1

    1

    試試這個代碼。因此,當您開始搜索時,搜索顯示控制器會將搜索界面疊加在原始視圖控制器的視圖上,如下所述:https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchDisplayController_Class/Reference/Reference.html

    您可能想要爲表格設置背景顏色或整個表格視圖由UISearchDisplayController提供,因此不透明。

    另外,您可以通過實施一個UISearchBar及其相關的委託方法篩選原始表:

    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { 
    
        //As the user enters search text filter the array that provides data to the UItableView you wish to filter 
    } 
    

    調查搜索欄委託在這裏:https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBarDelegate_Protocol/Reference/Reference.html

    感謝

    TG

    +0

    這適用於我!謝謝!但iOS7的半透明效果丟失了...是否有另一種方法來解決這個問題? – mzurita