[英]Two custom cells with search bar
I'm trying to have two custom cells and search bar in my UIView Controller. 我试图在UIView Controller中具有两个自定义单元格和搜索栏。 at first I was able to do one cell and search bar and it was perfect then I added another cell and then everything became ugly.
最初,我能够创建一个单元格和搜索栏,这是完美的,然后我添加了另一个单元格,然后一切变得丑陋。
Here is the idea of my custom cells I get data from my server in JSON. 这是我的自定义单元的想法,我从服务器以JSON获取数据。 Many shops, some of them have a design and some have no design.
许多商店,其中有些有设计,有些没有设计。 If a shop has a design I save the design in a variable as a string
withDesign
如果商店有设计,我会使用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)
The first cell is called design
and second is called Cell
第一个单元称为
design
,第二个Cell
称为Cell
I tried multiple ways but I failed because it's my first time to deal with two cells.
我尝试了多种方法,但失败了,因为这是我第一次处理两个单元。
What I'm tryting to do is all shops will be listed in Cell and if there is a shop that has a design then make cells with the design if no design then just list the shops. 我要尝试做的是,所有商店都将在Cell中列出,如果有一家商店有设计,那么如果没有设计,则用该设计制作单元,然后只列出商店。 Two separate customs cells
两个独立的海关牢房
What I'm trying to do 我想做什么
Any help will be appreciated! 任何帮助将不胜感激!
please Use code like this 请使用这样的代码
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.