UITapGestureRecognizer 不工作,直到我一直滚动到底部

问题描述

我在 UITableViewCell 的标签添加一个 UITapGestureRecognizer,但是只有在我滚动到表格底部后点击才有效。

一旦我滚动到底部,水龙头就可以完美运行并执行转场,但在我这样做之前,它不会调用函数

在滚动之前,我已经验证 if 语句确实评估为真,因此识别器在那里,但它不起作用。

任何关于原因的想法将不胜感激。

func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell",for: indexPath)
    for viewToRemove in cell.subviews {
        viewToRemove.removeFromSuperview();
    }
    
    let result = self.ResultArray[indexPath.row] as! NSDictionary;
    let width = self.frame.width;
    
    let rawTime = result["LogInDTM"] as? String;
    let rawUNIT = result[“unit”] as? String;
    let rawPersonID = result["PERS_ID"] as? String;
    let rawName = result["PERS_NAME"] as? String;
    let rawVehicle = result["Vehicle_ID"] as? String;
    let rawCall = result["CALL_NO"] as? String;
    
    var CleanVehicle = ""
    
    if let tmpVehicle = rawVehicle {
        CleanVehicle = tmpVehicle
    }
    
    var CleanCall = ""
    
    if let tmpCall = rawCall {
        CleanCall = tmpCall
    }
    
    var CleanUnit = ""
    
    if let tmpunit = rawUNIT {
        CleanUnit = tmpunit
    }
    
    //print(result);
    
    let cellView = UIView(frame: CGRect(x: 0,y: 0,width: width,height: 30));
    cellView.backgroundColor = .black;
    cellView.layer.cornerRadius = 5;
    cellView.layer.masksToBounds = true;
  
    let UnitLabel = UILabel(frame: CGRect(x: 2,width: width*0.15,height: 30));
    UnitLabel.textColor = .white;
    UnitLabel.layer.borderWidth = 1.0;
    UnitLabel.layer.borderColor = self.configuration.soOrange.cgColor;
    UnitLabel.text = " "+CleanUnit;
    UnitLabel.font = UIFont.systemFont(ofSize: 12,weight: UIFont.Weight(rawValue: 400));
    UnitLabel.adjustsFontSizetoFitWidth = true;
    cellView.addSubview(UnitLabel);
    
    let SubjectLabel = UILabel(frame: CGRect(x: (width*0.15)+2,width: width*0.4,height: 30));
    SubjectLabel.textColor = .white;
    SubjectLabel.layer.borderWidth = 1.0;
    SubjectLabel.layer.borderColor = self.configuration.soOrange.cgColor;
    SubjectLabel.text = " "+rawName!;
    SubjectLabel.font = UIFont.systemFont(ofSize: 12,weight: UIFont.Weight(rawValue: 400));
    SubjectLabel.adjustsFontSizetoFitWidth = true;
    cellView.addSubview(SubjectLabel);
    
    let VehicleLabel = UILabel(frame: CGRect(x: (width*0.55)+2,width: width*0.2,height: 30));
    VehicleLabel.textColor = .white;
    VehicleLabel.layer.borderWidth = 1.0;
    VehicleLabel.layer.borderColor = self.configuration.soOrange.cgColor;
    VehicleLabel.text = " "+CleanVehicle;
    VehicleLabel.font = UIFont.systemFont(ofSize: 12,weight: UIFont.Weight(rawValue: 400));
    VehicleLabel.adjustsFontSizetoFitWidth = true;
    cellView.addSubview(VehicleLabel);
    
    let CallLabel = UILabel(frame: CGRect(x: (width*0.75)+2,width: width*0.24,height: 30));
    CallLabel.textColor = .white;
    CallLabel.layer.borderWidth = 1.0;
    CallLabel.layer.borderColor = self.configuration.soOrange.cgColor;
    CallLabel.text = " "+CleanCall;
    CallLabel.font = UIFont.systemFont(ofSize: 12,weight: UIFont.Weight(rawValue: 400));
    CallLabel.adjustsFontSizetoFitWidth = true;
    
    if(CleanCall != ""){
        print(CleanCall);
        let callTap = UITapGestureRecognizer(target: self,action: #selector(self.openCall(_:)))
        CallLabel.isUserInteractionEnabled = true
        CallLabel.addGestureRecognizer(callTap)
    }
    
    
    
    cellView.addSubview(CallLabel);
    
    
    
    cell.addSubview(cellView);
    return cell;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)