UIGesture LongPress复制单元格

时间:2015-10-31 21:15:55

标签: ios swift uitableview

在我的tableview单元格中,我的UI经历了一个奇怪的交互漏洞。我实施了一个长按手势:

func handleLongPress(sender:UILongPressGestureRecognizer!) {

    var myCharacters: SelectedCharacter?
    let localLongPress = sender as UILongPressGestureRecognizer
    let locationInView = localLongPress.locationInView(cardsListed)
    let indexPath = charactersListed.indexPathForRowAtPoint(locationInView)
    let listed = frc.objectAtIndexPath(indexPath!) as! Characters
    let cell: firstCharacterDetails = charactersListed.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath!) as! firstCharacterDetails

    if listed == 0 {

    } else {

                if (sender.state == UIGestureRecognizerState.Ended) {
                    print("Long press Ended")
                } else if (sender.state == UIGestureRecognizerState.Began) {
                    let bounds: CGRect = UIScreen.mainScreen().bounds
                    let screenHeight: NSNumber = bounds.size.height
                    if screenHeight == 480 {
                        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                        let characterDetailsController: CharacterDetailsViewController = storyboard.instantiateViewControllerWithIdentifier("characterDetails") as! CharacterDetailsViewController
                        characterDetailsController.modalPresentationStyle = UIModalPresentationStyle.Popover
                        let popoverplayersCharacterController = characterDetailsController.popoverPresentationController
                        popoverCharacterNoteController?.permittedArrowDirections = .Any
                        popoverCharacterNoteController?.delegate = self
                        popoverCharacterNoteController?.sourceView = cell.cardDescription
                        characterDetailsController.characterDetails = listed
                        self.presentViewController(characterDetailsController, animated: true, completion: nil)

}

如果编码不完整,这是一个例子,因为我刚拿出这段代码供参考。现在我的问题是一个非常独特的问题,只有在用户意外手势时才会发生,但为了用户的安全,我想解决这个问题。

我面临的问题是,当用户长按手势时,如果他们用手指意外地拖动到另一个单元格,同时仍然按住单元格将实际复制自身或将其自身拖动到用户长按手势拖动的单元格下方至。我不确定如何防止这种情况发生,但如果有人有任何见解,将不胜感激!

1 个答案:

答案 0 :(得分:0)

发现我做错了什么。通过我第二次查看代码后,我意识到调用dequeueResuableCell是不正确的函数。我用以下代码切换代码行:

let cell: firstCharacterDetails = charactersListed.cellForRowAtIndexPath(indexPath!) as! firstCharacterDetails

问题解决了。当我复制并粘贴一些我在几个不同控制器中重复使用的代码时,我没有想太多。