菜单控制器未出现在自定义单元格上

时间:2017-01-21 10:00:18

标签: ios uitableview menuitem tableviewcell uimenucontroller

我的目标是在Cell上打开MenuController,当我长按每个单元格需要鞋子菜单时就像默认的复制粘贴选项一样,这里我添加了打开菜单控制器的手势但是每次都无法打开,alos成为FirstResponder()总是返回false,提前谢谢请帮忙。

class InComingTextCell: UITableViewCell {

@IBOutlet weak var message: UILabel!
@IBOutlet weak var time: UILabel!
@IBOutlet weak var mainView: UIView!

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    mainView.layer.cornerRadius = 8
    mainView.layer.masksToBounds = true

    let tapGesture = UILongPressGestureRecognizer.init(target: self, action: #selector(DetailsViewController.tapGesture(sender:)))
     self.addGestureRecognizer(tapGesture)

    // Configure the view for the selected state
}

    // MARK:- LongPress GestureRecognizer Action Method

  func tapGesture(sender: UILongPressGestureRecognizer){

    let parentVC = self.getParentViewController as! DetailsViewController!

    if !(parentVC?.tableView.isEditing)!{

        let Cell = sender.view as! InComingTextCell

       // let touch = sender.location(in: parentVC?.tableView)
        //let selectedIndexPath = parentVC?.tableView.indexPathForRow(at: touch)

       // let messageInfo = parentVC?.getMessageInfoFromIndex(selectedIndexPath: selectedIndexPath!)

        let first = UIMenuItem.init(title: "Delete", action: #selector(DetailsViewController.deleteItmeMenuAction(sender:)))
        let Second = UIMenuItem.init(title: "Forward", action: #selector(DetailsViewController.deleteItmeMenuAction(sender:)))

        //becomeFirstResponder()
        let menuController = UIMenuController.shared
        //menuController.arrowDirection = .right
        menuController.menuItems = [first,Second]
        menuController.setTargetRect(Cell.frame, in: Cell.mainView)
        menuController.setMenuVisible(true, animated: true)


    }
}

}

0 个答案:

没有答案