Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS快捷搜索栏_Ios_Uitableview - Fatal编程技术网

iOS快捷搜索栏

iOS快捷搜索栏,ios,uitableview,Ios,Uitableview,我是Swift的初学者 我目前正在实现一个搜索栏,可以搜索多个字段 据我所知,我们需要一个用于iOS swift搜索栏的数组 下面是我目前拥有的代码。我不知道为什么我的搜索没有结果,我已经确认我的数组中有数据 updateSearchResultsForSearchController func updateSearchResultsForSearchController(searchController: UISearchController) { filtered.removeAll

我是Swift的初学者

我目前正在实现一个搜索栏,可以搜索多个字段

据我所知,我们需要一个用于iOS swift搜索栏的数组

下面是我目前拥有的代码。我不知道为什么我的搜索没有结果,我已经确认我的数组中有数据

updateSearchResultsForSearchController

func updateSearchResultsForSearchController(searchController: UISearchController) {
    filtered.removeAll(keepCapacity: false)

    for i in 0...arrProcessName.count{

        if(arrProcessName[safe: i] != nil && arrRequestedBy[safe: i] != nil && arrCreationTime[safe: i] != nil && arrStatus[safe: i] != nil)
        {
        allItems += [(process:arrProcessName[i], requestor:arrRequestedBy[i], creation:arrCreationTime[i], status:arrStatus[i])]
        }
    }
    tableView?.reloadData()
}
搜索栏

func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
    print("testing", searchText)
    filtered = allItems.filter({ data in
        let tmp: NSString = data.process
        let range = tmp.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)
        return range.location != NSNotFound
    })
    if(filtered.count == 0){
        searchActive = false;
    } else {
        searchActive = true;
    }
    tableView?.reloadData()
}
桌面视图

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if self.searchCtrler.active {
        return filtered.count
    } else {
        return arrRequestedBy.count
    }
}
带有indexath的tableView

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    removeProgressBar()
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! HistoryCustomCell

    cell.selectionStyle = .None
    cell.accessoryType = UITableViewCellAccessoryType.None

    if self.searchCtrler.active {
        cell.lbl_request_name.text = filtered[indexPath.row].process
        cell.lbl_requested_by.text = filtered[indexPath.row].requestor
        cell.lbl_creation_time.text = filtered[indexPath.row].creation
        cell.lbl_status.text = filtered[indexPath.row].status
    } else {
        cell.lbl_request_name.text = arrProcessName[indexPath.row]
        cell.lbl_requested_by.text = "Requested by: " + arrRequestedBy[indexPath.row]
        cell.lbl_creation_time.text = arrCreationTime[indexPath.row]
        cell.lbl_status.text = arrStatus[indexPath.row]

        switch arrStatus[indexPath.row] {
            case "Completed", "Approved":
                cell.img_status.image = UIImage(named: "ic_approved")
            case "Running", "Processing", "Pending":
                cell.img_status.image = UIImage(named: "ic_pending")
            case "Denied", "Rejected":
                cell.img_status.image = UIImage(named: "ic_reject")
            case "Error":
                cell.img_status.image = UIImage(named: "ic_terminated")
            case "Retracted":
                cell.img_status.image = UIImage(named: "ic_retracted")
            default:
                cell.img_status.image = UIImage(named: "")
        }
    }

    return cell
}

我现在的情况是,当我使用搜索栏时,我没有得到任何结果。请帮忙。我真的找不到太多关于在互联网上有多个搜索字段的信息。您的回答将不胜感激。

检查筛选列表是否在方法updateSearchResultsForSearchController中有值。如果搜索栏处于活动状态,请将筛选数组带到populate@SubinKKuriakose筛选的列表为空。我现在面临的问题是。我不知道如何从updateSearchResultsForSearchController函数调用searchBar函数,似乎您是在添加从未使用过的“allItems”。filtered=allItems。是的,刚刚尝试了filtered=allItems。现在有数据了。但是我的过滤器坏了。因为我使用的是元组,如果筛选列表在方法updateSearchResultsForSearchController中有值,我不知道为什么不能使用谓词进行元组检查。如果搜索栏处于活动状态,则将筛选数组populate@SubinKKuriakose筛选的列表为空。我现在面临的问题是。我不知道如何从updateSearchResultsForSearchController函数调用searchBar函数,似乎您是在添加从未使用过的“allItems”。filtered=allItems。是的,刚刚尝试了filtered=allItems。现在有数据了。但是我的过滤器坏了。因为我使用的是元组,我不知道为什么不能对元组使用谓词