清除表格视图基于日期过滤器

时间:2018-07-02 17:16:34

标签: swift uitableview

您好,我想尝试使用日期选择器创建搜索栏。 当我尝试清除表视图时,如果搜索不匹配。但由于某种原因我不能

我试图清除我的数组并重新加载tableview,但是仍然无法正常工作。 我也试图返回基于布尔触发器的索引原始计数为零没有工作。

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell =  tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! CustomTableViewCell

        client = clinetarr[indexPath.row]


cell.message.numberOfLines=0
        if doneclick == true{
            for i in 1..<client.count{
            if let date = client["date"] as? String {

                let dateee = "\(date)"
                let last = dateee.prefix(10)
                let y = last.count
                print ("here is x \(last)")
                if last == "\(dateString)" {

                    for i in 1..<client.count{
                        index = "\(i) " 

                    }
                    if let date = client["date"] as? String {
                        datee = "\(date) "  
                    }

                    if let response = client["response"] as? String {
                        //            resp = "\(response) "
                        let x = "\(response) "
                        print ("\(x) ")
                        if x.contains("1"){
                            resp = "Present"
                        }
                        else if x.contains("2"){
                            resp = "Absent"
                        }

                        else if x.contains("3"){
                            resp = "Tardy"
                        }

                    }

                    if let message = client2["message"] as? String {
                        output = message
                    }
                }
                else{

                }

            }
            }

        }else{
        if let i = client["index"] as? String {
            index = "\(i) "  //using space as separator

        }

        if let date = client["date"] as? String {

            datee = "\(date) "  //using space as separator


        }


        if let response = client["response"] as? String {

            let x = "\(response) "

            if x.contains("1"){
                resp = "Present"
            }
            else if x.contains("2"){
                resp = "Absent"
            }

            else if x.contains("3"){
                resp = "Tardy"
            }

        }

        if let message = client["message"] as? String {
            output = message
        }
        }
        cell.indextnumber.text = index
        cell.response.text = resp
        cell.date.text = datee
        cell.message.text = output

        return cell
    }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

尝试删除行或整个部分,而不是重新加载表视图。

var rowsToDelete: [Int] = []
for r in 0...(myArray.count-1) {
     rowsToDelete.append(r)
}


tableView.beginUpdates()
self.tableView!.deleteRows(at: rowsToDelete, with: UITableViewRowAnimation.left)
tableView.endUpdates()