如何在单元格单击时过滤tableView单元格,如果单元格textField在swift中具有从按钮名称开始的字符串

时间:2018-08-25 11:02:39

标签: ios swift tablefilter

我要在单击按钮时过滤tableView单元格,如果该单元格的一个元素具有与按钮代码相同的字符串,请显示该单元格。 Button是集合视图单元格,所有按钮都有一些代码。当我单击第一个按钮单元格时,表需要过滤具有与按钮代码相同的值的单元格。

//Button UICollectionView 

    func collectionView(_ collectionView: UICollectionView, cellForItemAt 
     indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: 
       "buttonCell", for: indexPath as IndexPath) as! SPCollectionViewCell


        // static cell
        if (indexPath.row == 0) {
            cell.zoneLbl?.text = "All"
            code = "00"
        }else{
            var item2 = self.zoneList[indexPath.row - 1]
            code = item2["ListID"] as? String
            cell.zoneLbl?.text = item2["ListName"] as? String
         }
       return cell
       }

//TableView

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

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

        let item = self.listData[indexPath.row]
        ZoneCategoryID =  item["ZoneCategoryID"]  as? String

        cell.serviceProviderName?.text = (item["CompanyName"] as? String)?.uppercased()
        cell.addressLbl?.text = item["Address"] as? String
        cell.emailLbl?.text = item["Email"] as? String
        cell.mobileNoLbl?.text = item["Phone"]  as? String
        zonee =  item["ListName"]  as? String
        TypeId = item["TypeID"]  as? String
        ServiceWellnessID =  item["ServiceWellnessID"]  as? String

       return cell
}

此处的“代码”值与“ ZoneCategoryID”相同。 预先感谢。

0 个答案:

没有答案