簡體   English   中英

搜索結果TableView調整問題

[英]Search Results TableView adjusting problems

我在通過表格視圖搜索項目時遇到問題。 問題是,當我搜索某些內容時,應用程序將顯示一個新的表格視圖,結果是在很小的單元格中看不到任何東西(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
}

在這里,您可以看到加載項目時的外觀(忽略圖像)

這是我嘗試搜索時發生的情況

我解決了 我只需要添加以下行:

        searchDisplayController?.searchResultsTableView.rowHeight = 100

在viewDidLoad中,單元格大小已更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM