2015-07-29 1 views
0

У меня проблема с поиском элементов через табличный вид. Проблема в том, что при поиске чего-то приложение отображает новое представление таблицы, результаты которого находятся в действительно маленьких ячейках, где невозможно ничего увидеть (2 метки и 1 изображение). Поэтому мой вопрос заключается в том, как я могу настроить отображаемые высоты ячеек, ширину и настроить другие элементы в searchResultsTableView. Я могу предоставить вам свой код, если он поможет решить проблему.Результаты поиска TableView для настройки

Заранее спасибо

Вот мой код:

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    if tableView == self.searchDisplayController!.searchResultsTableView { 
     return self.filteredCandies.count 
    } else { 
     return self.candies.count 
    } 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CellTableViewCell 

    var candy : Candy 

    // Check to see whether the normal table or search results table is being displayed and set the Candy object from the appropriate array 

    if tableView == self.searchDisplayController!.searchResultsTableView { 
     candy = filteredCandies[indexPath.row] 
    } else { 
     candy = candies[indexPath.row] 
    } 

    cell.label1.text = candy.name 

    //cell.label2.text = candy.category 
    cell.contentView.frame = cell.bounds 
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 

    let item = candies[indexPath.row] 
    cell.setCell(item.name, imageName: item.imageName) 

    return cell 
} 

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 


    tableView.deselectRowAtIndexPath(indexPath, animated: true) 

    var candy : Candy 

    if (tableView == self.searchDisplayController?.searchResultsTableView) 
    { 
     candy = self.filteredCandies[indexPath.row] 
    } 
    else 
    { 
     candy = self.candies[indexPath.row] 
    } 

    let infoViewController: InfoViewController = self.storyboard?.instantiateViewControllerWithIdentifier("InfoViewController") as! InfoViewController 

    infoViewController.label01 = candy.name 
    infoViewController.label02 = candy.category 
    infoViewController.imageFile = candy.imageName 


    self.presentViewController(infoViewController, animated: true, completion: nil) 
} 

func filterContentForSearchText(searchText: String, scope: String = "All") { 
    // Filter the array using the filter method 
    self.filteredCandies = self.candies.filter({(candy: Candy) -> Bool in 

     let categoryMatch = (scope == "All") || (candy.category == scope) 

     let stringMatch = candy.name.rangeOfString(searchText.lowercaseString) 

     return categoryMatch && (stringMatch != nil) 





    }) 
} 

func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String!) -> Bool { 
    self.filterContentForSearchText(searchString) 


      return true 
} 

func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchScope searchOption: Int) -> Bool { 
    self.filterContentForSearchText(self.searchDisplayController!.searchBar.text) 
    return true 
} 

here you can see how it looks when i load the project (ignore the images)

and here is what happens when I try to search

+0

предоставьте код. – random

+0

Я представил код и некоторые изображения. Пожалуйста помоги –

ответ

0

я решил его. Мне просто пришлось добавить эту строку:

 searchDisplayController?.searchResultsTableView.rowHeight = 100 

в видеDidLoad и размер ячейки изменен.

 Смежные вопросы

  • Нет связанных вопросов^_^