I am very new to iOS. I am trying to show a pop up menu,but some how I am unable to display menu. Please help.
Here is my code:
//DidLoad function to initialize UILongPRessGestureRecognizer
override func viewDidLoad()
{
super.viewDidLoad()
var longprss : UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: Selector("display:"))
self.tableView.addGestureRecognizer(longprss)
}
//Bool function Can become first responder set to true
override func canBecomeFirstResponder() -> Bool {
return true
}
//become first responser set to true
override func becomeFirstResponder() -> Bool {
return true
}
//action handler of longPressGesture
func display(gesture: UILongPressGestureRecognizer)
{
self.becomeFirstResponder()
println("Is first responder")
var menu = UIMenuController.sharedMenuController()
var deleteItem = UIMenuItem(title: "Delete", action: Selector("deleteLine"))
var editItems = UIMenuItem(title: "Edit", action: Selector("editrow"))
menu.menuItems = [deleteItem ,editItems]
menu.setTargetRect(CGRect(x: 100, y: 80, width: 100, height: 50), inView: UIView())
menu.setMenuVisible(true, animated: true)
}
//perform action method
override func tableView(tableView: UITableView, performAction action: Selector, forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject!) {
}
//can perform action method.
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
if action == Selector("Delete")
{
return true
}
return false
}
Please help me to display popup menu.
Thank you in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…