出现“鬼”视图

时间:2017-08-21 05:53:40

标签: ios swift

为了更清晰地查找我的应用程序,我的表格视图中的每个单元格都有一个额外的视图,原始的单元格与背景相匹配。每个单元格还与文档文件夹中的视频相关联。我进行了设置,以便重命名视频。但是,一旦重命名任何视频,就会出现“重影”视图。我完全不知道为什么甚至如何做到这一点。这是改名的地方:

do {

    var urlMOV = cell.videoURL!
    let JPGdelete = cell.urlJpg
    var valuesMOV = URLResourceValues.init()

    if ((alertAlCon.textFields!.first?.text?.characters.count)! >= 15){=


        let tmAlcon = UIAlertController(title: "Too Long", message: "The name you entered is too long", preferredStyle: .alert)

        let tmCancelAl = UIAlertAction(title: "Cancel", style: .cancel, handler: {action in

            self.present(alertAlCon, animated: true, completion: nil)
            })


        tmAlcon.addAction(tmCancelAl)
        self.present(tmAlcon, animated: true, completion: nil)

    }

    if ((alertAlCon.textFields!.first?.text?.characters.count)! <= 14){

        valuesMOV.name = (alertAlCon.textFields!.first?.text)! + ".mp4"
        try urlMOV.setResourceValues(valuesMOV)
        try! FileManager().removeItem(at: JPGdelete!)
    }
}


catch {
    Swift.print("Error in rewrite ", error)
}

这是额外观点的地方:

let rectangle = CGRect(x: 0, y: 0, width: parent.view.frame.width, height: 88)
let myView : UIView = UIView(frame: rectangle)
myView.center = self.center
myView.backgroundColor = UIColor.white
self.contentView.addSubview(myView)
self.contentView.sendSubview(toBack: myView)

以下是正在发生的事情的截图:

Before the name is changed

After the name is changed

有没有人知道为什么会发生这种情况????

1 个答案:

答案 0 :(得分:1)

在Bilal的帮助下,发现我的额外视图功能不断向我的单元格添加更多视图,因为我必须在表格视图中重新加载数据。我能够通过在单元格的子视图中查看我的额外视图标记来修复它,并删除该视图(如果它在那里)。这是功能:

func setViews(){

    let selectedView = UIView()
    selectedView.backgroundColor = UIColor.init(red: 0.0/255.0, green: 75.0/255.0, blue: 150.0/255.0, alpha: 0.25)
    self.selectedBackgroundView = selectedView

    if let viewWithTag = self.contentView.viewWithTag(821){

        viewWithTag.removeFromSuperview()

    }

    let rectangle = CGRect(x: 0, y: 0, width: parent.view.frame.width, height: 88)
    let myView : UIView = UIView(frame: rectangle)
    myView.center = self.contentView.center
    myView.backgroundColor = UIColor.white
    myView.tag = 821
    self.contentView.addSubview(myView)
    self.contentView.sendSubview(toBack: myView)

}