【问题标题】:Search Results TableView adjusting problems搜索结果 TableView 调整问题
【发布时间】:2015-07-29 14:02:25
【问题描述】:

我在通过表格视图搜索项目时遇到问题。 问题是,当我搜索某些内容时,应用程序会显示一个新的表格视图,这会导致在非常小的单元格中看不到任何东西(2 个标签和 1 个 imageView)。所以我的问题是如何在 searchResultsTableView 中调整显示的单元格高度、宽度和配置其他元​​素。 如果它有助于解决问题,我可以为您提供我的代码。

提前致谢

这是我的代码:

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
}

【问题讨论】:

  • 请提供代码。
  • 我提供了代码和一些图片。请帮忙

标签: ios swift xcode6 uisearchdisplaycontroller


【解决方案1】:

我解决了。我只需要添加这一行:

        searchDisplayController?.searchResultsTableView.rowHeight = 100

在 viewDidLoad 中,单元格大小发生了变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多