1

Morning,

I need help. I Want to display I want to display UItextfield error messages Error with UImenuController but this don't work. My UItextfield is in UITaBleView cell.!

my class

@IBOutlet weak var passwordField: UITextField!  


    func textFieldDidEndEditing(textField: UITextField) {

        if textField == passwordField && !Validation.isValidPassword(textField.text){
            displayMenu(textField, errorMessage : "error message")
        }

    }


    func displayMenu(view : UITextField , errorMessage : String){

        let menuItem : UIMenuItem = UIMenuItem(title: errorMessage , action: Selector("showMenu"))
        var menu : UIMenuController = UIMenuController()

        menu.arrowDirection = UIMenuControllerArrowDirection.Up
        menu.menuItems = [menuItem as AnyObject]

        menu.setTargetRect(CGRect(x: 0, y: 0, width: 100, height: 50), inView: self.tableView)
        menu.setMenuVisible(true, animated: true)

        println("display menu")

    }


    func showMenu() {
        println("menu show");
    }



    override func canBecomeFirstResponder() -> Bool {
        return true
    }

    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {

        if action == Selector("showMenu") {
            return tableView.canPerformAction(action, withSender: sender)
        }
        return false
    }

error

2015-02-21 17:54:03.576 Lovia[7870:177566] *** Assertion failure in -[UIMenuController init], /SourceCache/UIKit_Sim/UIKit-3347.6.1/UIMenuController.m:90
2015-02-21 17:54:03.585 Lovia[7870:177566] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIMenuController instance.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001026e4b95 __exceptionPreprocess + 165
    1   libobjc.A.dylib       

Thanks

Christian
  • 22,585
  • 9
  • 80
  • 106

1 Answers1

0

if you need to show MenuItem in cells you can check: How to show a custom UIMenuItem for a UITableViewCell?

Another problem in canPerformAction:

 override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {

    if action == Selector("showMenu") {
        return true
    }
    return false
}
Community
  • 1
  • 1
Miguel
  • 957
  • 10
  • 12