微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 icarousel 当前索引项中使用搜索?

如何解决如何在 icarousel 当前索引项中使用搜索?

嘿,我只是想知道如何使用搜索栏重新加载轮播项目中的数据而不重新加载所有其他项目?

以下是轮播代码

要注意的是if == "Languages"

lazy var car:iCarousel = {
        let view = iCarousel()
        view.frame = CGRect(x:0,y:Int(CGFloat(Double(Int(Float(bounds.size.height*0.05))) + globW  )),width: Int(Float(bounds.size.width)*0.85),height: Int(Float(bounds.size.height)*0.75))
//        view.type = .coverFlow
        view.type = .wheel
        view.isvertical = true
        view.bounces = true
        view.decelerationRate = 0.0
        view.clipsToBounds=true
//        view.isScrollEnabled = false
//        view.backgroundColor = .red

        return view
    }()

以下是轮播项目的相关案例:

case "C":
                
                let titleV:UILabel!
                let titleOption:NSMutableAttributedString!
                let fSAttr = [ NSAttributedString.Key.font: UIFont(name: "Helvetica",size: bounds.size.width*0.04)!,NSAttributedString.Key.foregroundColor : UIColor.white,]

                titleOption = NSMutableAttributedString(string:currentField[index].placeholder!,attributes: fSAttr)
                let widthFS = titleOption.width(containerHeight: v.bounds.width*0.5)
        
                img.frame=CGRect(x: Double(v.bounds.width)*0.5-Double(bounds.size.width)*0.05,y: Double(v.bounds.height)*0.2,width:Double(bounds.size.width)*0.1,height: Double(bounds.size.width)*0.1)
           
                img.image=UIImage(named: currentField[index].path!)?.resized(to: CGSize(width: CGFloat(bounds.size.width*0.1),height: CGFloat(bounds.size.width*0.1)))
                v.addSubview(img)
                
                titleV = UILabel(frame: CGRect(x:Int((v.bounds.width - widthFS)*0.5),y: Int(-v.bounds.height*0.02),width: Int(Float(0.449*bounds.size.height)),height: Int(Float(0.567*bounds.size.height))))
                titleV.backgroundColor = .clear
                titleV.attributedText = titleOption
//                v.bounds.height*0.33
//                titleV.isEditable = false
                v.addSubview(titleV)
                currentCarView = v
                if currentField[index].id == "Languages"{
                    let cont=UITextField()
                    //  TRY TO RELOAD V AND VIEW
                    // find children and an id
                    
          
//                        https://www.youtube.com/watch?v=mMr8fg5LZcU
                    
//                    https://www.raywenderlich.com/4363809-uisearchcontroller-tutorial-getting-started
                   
                    cont.tag = index
//                    cont.text = topkol
//                    cont.becomeFirstResponder()
                    cont.textColor = .white
                    cont.attributedplaceholder = NSAttributedString(string: "Search",attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray])
                    cont.setBottomBorder(color:UIColor.gray.cgColor)
                    cont.frame = CGRect(x: CGFloat(Int(Float(car.bounds.width*0.4))),y: v.bounds.height*0.5 /*CGFloat(Int(Float(car.frame.height*0.5)))-25*/,width:CGFloat(Int(Float(car.bounds.width*0.6))),height: 50)
                    cont.backgroundColor = .clear
                    cont.addTarget(self,action: #selector(editSearch(_:)),for: UIControl.Event.editingChanged)
                    cont.addTarget(self,for: .editingDidEndOnExit)
                    v.addSubview(cont)
                }
                for n in 0..<currentField[index].selections!.count{
                    let buttonVal = UIButton()
                    buttonVal.tag = index
                    buttonVal.accessibilityIdentifier = currentField[index].selections![n]
              
                    if currentField[index].id == "Languages"{
                    
                        
                        //replace with search array currentField[index].selections![n]
                        let languageComponent: [String] = currentField[index].selections![n].components(separatedBy: "-");
                           let lastElement = languageComponent[languageComponent.count - 1];
//                            let elem = languageComponent

//
                        let b = (n)/4
                        let x = 0.2 +  Double(Int(Double((n))-floor(Double(b))*4))*0.2
                        let y = 0.1*floor(Double(b)) //0.05 0.55 0.1
                        
//                        Double(v.bounds.height)*y
                        buttonVal.frame=CGRect(x: Double(v.bounds.width)*Double(round(x*10)/10)-12.5,y:  Double(v.bounds.height)*y,width:Double(v.bounds.width)*0.11,height: Double(v.bounds.width)*0.11)
                        buttonVal.setTitle(countryFlag(country: lastElement),for: .normal)
                      
                        Scroll.contentSize.height = CGFloat(Double(v.bounds.height)*y)+CGFloat(Double(v.bounds.height)*0.1)
                        Container.frame.size = CGSize(width: car.bounds.width,height: Scroll.contentSize.height)
                        Container.addSubview(buttonVal)
                        Scroll.addSubview(Container)
                        if !Scroll.isDescendant(of: v){
                            v.addSubview(Scroll)
                        }
                      
//                        v.backgroundColor = .green
                       
//                        print(countryName(countryCode: "DE")!)
          
                    } else {
                        let x = n == 0 ? 0.2 : n == 1 ? 0.5 : 0.8
    //                    print("the W",v.bounds.width)
                        buttonVal.frame=CGRect(x: Double(v.bounds.width)*Double(x)-12.5,y: Double(v.bounds.height)*0.6,height: Double(v.bounds.width)*0.11)
                        
                        let imageVal = UIImage(named: currentField[index].selections![n])?.resized(to: CGSize(width: CGFloat(bounds.size.width*0.1),height: CGFloat(bounds.size.width*0.1)))

                    buttonVal.setimage(imageVal!.resized(to: CGSize(width: v.bounds.width*0.075,height: v.bounds.width*0.075)),for: .normal)
                        v.addSubview(buttonVal)
                    }

                    buttonVal.layer.cornerRadius = v.bounds.width*0.055
                  
                    if currentField[index].id == "Gender" {
                        if currentField[index].text == currentField[index].selections![n]{
                            //HERE
                            buttonVal.backgroundColor = .white
                        }
                    selArr.append(selButtons(name:buttonVal,tag:index))
                    } else {
                        for r in 0..<currentField[index].selected!.count{
                            if currentField[index].selections![n] == currentField[index].selected![r] {
                            buttonVal.backgroundColor = .white
                            }
                        }
                    }
                    
             
                    buttonVal.addTarget(self,action: #selector(editTypeC(_:)),for: UIControl.Event.touchDown)
                }

这里是编辑功能

@objc func editSearch(_ sender:UITextField){
      
        dispatchQueue.main.async { [self] in
            sender.text = sender.text!
            
            currentCarView.backgroundColor = .red
     car.reloadData()
            car.currentItemView?.reloadInputViews()
        }
 
  
    }

谢谢大家的物品。建议更好的方法

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。