繁体   English   中英

带搜索栏的两个自定义单元格

[英]Two custom cells with search bar

我试图在UIView Controller中具有两个自定义单元格和搜索栏。 最初,我能够创建一个单元格和搜索栏,这是完美的,然后我添加了另一个单元格,然后一切变得丑陋。

这是我的自定义单元的想法,我从服务器以JSON获取数据。 许多商店,其中有些有设计,有些没有设计。 如果商店有设计,我会使用Design将设计保存为字符串withDesign的变量

                let shop_id = subJson["id"].stringValue
                var info = Shops(shopname: shopName, Logo: logoString, family_id: familiy_id , design : designImage )
                 self.withDesign = self.shops.filter { $0.design != "" }
                 self.withOut =  self.shops.filter { $0.design == "" }
                 self.allShops = self.NofilteredArr + self.filteredArr
                print(self.filteredArr)

第一个单元称为design ,第二个Cell称为Cell

在此处输入图片说明 在此处输入图片说明

在此处输入图片说明 我尝试了多种方法,但失败了,因为这是我第一次处理两个单元。

我要尝试做的是,所有商店都将在Cell中列出,如果有一家商店有设计,那么如果没有设计,则用该设计制作单元,然后只列出商店。 两个独立的海关牢房

我想做什么

设计实例

单元格的例子

任何帮助将不胜感激!

请使用这样的代码

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

    if searchActive
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ShopTableViewCell
        let entry1 = auxiliar?[indexPath.row]
        cell.shopImage.hnk_setImage(from: URL(string: (entry1?.Logo)!))
        cell.shopName.text = entry1?.shopname
        return cell

    }else{
        if withDesign != nil
        {
            let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ShopTableViewCell

            let entry = withDesign[indexPath.row]

            cell.shopImage.hnk_setImage(from: URL(string: entry.Logo))
            cell.shopName.text = entry.shopname
            return cell

        } else {

            let cell = tableView.dequeueReusableCell(withIdentifier: "design", for: indexPath) as! DesignTableViewCell
            let entry = withDesign[indexPath.row]

            cell.deignImage.hnk_setImage(from: URL(string: entry.design))
            return cell

        }
    }

暂无
暂无

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

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