canEditRowAtIndexPath适用于快速滑动

时间:2016-09-03 08:40:58

标签: ios swift uitableview uigesturerecognizer

我在项目中使用this弹出窗口。在我的ViewController课程中,我使用(UITapGestureRecognizerUILongPressGestureRecognizer)和左,右,上,下UISwipeGestureRecognizer。在我的弹出类中,我创建了tableView。当我使用ViewController显示弹出窗口时tableView课程中,canEditRowAtIndexPath无法正常工作,只有在行上超快速滑动时才有效。我尝试通过在两个课程中添加shouldRecognizeSimultaneouslyWithGestureRecognizer来解决此问题,但这对我没有用。任何人都知道如何解决它。 感谢。

在PopUp Show

期间在我的ViewController类中尝试此操作
  if view.gestureRecognizers != nil {
            for gesture in view.gestureRecognizers! {
                if let recognizer = gesture as? UISwipeGestureRecognizer {
                    view.removeGestureRecognizer(recognizer)
                }
            }
        }

PopUp Class enter image description here

class PopUp: UIView, UIWebViewDelegate, UITableViewDelegate, UIGestureRecognizerDelegate {
    var closeButtonHandler: (() -> Void)?

    @IBOutlet weak var tableView: UITableView!
    @IBOutlet private var closeButton: UIButton!
    @IBOutlet private var contentView: UIView!

     func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return pageNameUserDefaults.count
    }

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ImageCell
        cell.bookmarkName.text = pageNameUserDefaults[indexPath.row]
        cell.bookmarkImage.image = pageIconUserDefaults[indexPath.row]
//        cell.bookmarkName.userInteractionEnabled = false
        return cell
    }

     func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
    }

     func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

        print("commitEditingStyle mode")

        if (editingStyle == UITableViewCellEditingStyle.Delete) {
            // handle delete (by removing the data from your array and updating the tableview)
            pageNameUserDefaults.removeAtIndex(indexPath.row)
            pageLinkUserDefaults.removeAtIndex(indexPath.row)
            pageIconUserDefaults.removeAtIndex(indexPath.row)

            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)

        }
    }
    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }

//    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
//        return true
//    }


    override func awakeFromNib() {
        super.awakeFromNib()
        self.configure()

    }

    private func configure() {

        self.contentView.layer.cornerRadius = 5.0
        self.closeButton.layer.cornerRadius = CGRectGetHeight(self.closeButton.bounds) / 2.0
        self.closeButton.layer.shadowColor = UIColor.blackColor().CGColor
        self.closeButton.layer.shadowOffset = CGSizeZero
        self.closeButton.layer.shadowOpacity = 0.3
        self.closeButton.layer.shadowRadius = 2.0
        tableView.registerNib(UINib(nibName: "ImageCell", bundle: nil), forCellReuseIdentifier: "cell")
//        tableView.allowsSelectionDuringEditing = true
//        tableView.allowsSelection = true

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(PopUp.loadList(_:)),name:"load", object: nil)
    }

    func loadList(notification: NSNotification){
        self.tableView.reloadData()
    }

    class func instantiateFromNib() -> PopUp {
        let view = UINib(nibName: "PopUp", bundle: nil).instantiateWithOwner(nil, options: nil).first as! PopUp

        return view
    }

    @IBAction func handleCloseButton(sender: UIButton) {
        self.closeButtonHandler?()
    }

}

在ViewController中显示PopUp的方法

let popUpView = PopUp.instantiateFromNib()

let window = UIApplication.sharedApplication().delegate?.window!
        let modal = PathDynamicModal()
        modal.showMagnitude = 200.0
        modal.closeMagnitude = 130.0
        popUpView.closeButtonHandler = {[weak modal] in
            modal?.closeWithLeansRandom()
            return
        }
        popUpView.bottomButtonHandler = {[weak modal] in
            modal?.closeWithLeansRandom()
            print("bottom button")

            return
        }
        modal.show(modalView: popUpView, inView: window!)

0 个答案:

没有答案