Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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_Swift_Uitableview_Uisearchbar - Fatal编程技术网

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

Ios 带有搜索栏的两个自定义单元格,ios,swift,uitableview,uisearchbar,Ios,Swift,Uitableview,Uisearchbar,我试图在UIView控制器中有两个自定义单元格和搜索栏。起初,我能做一个单元格和搜索栏,它很完美,然后我添加了另一个单元格,然后一切变得丑陋 这是我的自定义单元格的想法 我从服务器获取JSON格式的数据。许多商店,有些有设计,有些没有设计。如果一家商店有一个设计,我将该设计保存在变量中,作为字符串withDesign let shop_id = subJson["id"].stringValue var info = Shops(s

我试图在UIView控制器中有两个自定义单元格和搜索栏。起初,我能做一个单元格和搜索栏,它很完美,然后我添加了另一个单元格,然后一切变得丑陋

这是我的自定义单元格的想法 我从服务器获取JSON格式的数据。许多商店,有些有设计,有些没有设计。如果一家商店有一个设计,我将该设计保存在变量中,作为字符串
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

我尝试了多种方法,但我失败了,因为这是我第一次处理两个细胞

我试着做的是所有的商店都会列在单元格中,如果有一家商店有设计,那么用设计制作单元格。如果没有设计,那么只列出商店。两个单独的海关单元

我想做什么


任何帮助都将不胜感激

请使用这样的代码

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

        }
    }

你的代码不好,请使用if-else条件,这就是我在这里问的原因!我举了一个例子,它给出了致命错误:在
let entry=withDesign[indexPath.row]
中索引超出范围请调试代码并检查withDesign数组中的变量数withDesign的数目是正确的。我试着做的是所有的商店都会列在
单元格中,如果有一家商店有设计,那么用设计制作单元格。如果没有设计,那么只列出商店。两个独立的客户呼叫扫描您编辑问题的源代码和致命错误屏幕快照您能再次看到我的问题吗