简体   繁体   English

搜索结果TableView调整问题

[英]Search Results TableView adjusting problems

I have a problem with searching items through a table view. 我在通过表格视图搜索项目时遇到问题。 The problem is that when I search something the app displays a new table view, which results are in really small cells where it is impossible to see anything (2 labels and 1 imageView). 问题是,当我搜索某些内容时,应用程序将显示一个新的表格视图,结果是在很小的单元格中看不到任何东西(2个标签和1个imageView)。 So my question is how can I adjust the displayed cells height, width and configure other elements in the searchResultsTableView. 因此,我的问题是如何调整显示的单元格的高度,宽度并配置searchResultsTableView中的其他元素。 I can provide you with my code if it helps resolving the problem. 如果可以帮助您解决问题,我可以为您提供代码。

Thanks in advance 提前致谢

Here is my code: 这是我的代码:

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
}

在这里,您可以看到加载项目时的外观(忽略图像)

这是我尝试搜索时发生的情况

I resolved it. 我解决了 I just had to add this line: 我只需要添加以下行:

        searchDisplayController?.searchResultsTableView.rowHeight = 100

in the viewDidLoad and the cell size changed. 在viewDidLoad中,单元格大小已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM