2016-05-20 8 views
0

Ich habe ein Problem beim Auffinden der UIview/Casting von UImenuItem und UILongPressGestureRecognizer. Ich kann den Kopiebutton sehen, aber sobald ich klicke, habe ich einen Castingfehler.Swift Fehler, UIMenuItem zu UIview/UIlabel für Kopie

Unten ist mein Code

ViewDidLoad

let copyLongPress = UILongPressGestureRecognizer(target: self, action: #selector(OfficeMapController.handleLongPress(_:))) 

self.addressView.addGestureRecognizer(copyLongPress) 



    func handleLongPress(longPressView :UILongPressGestureRecognizer) { 
    becomeFirstResponder() 
    let menu = UIMenuController.sharedMenuController() 
    let copyItem = UIMenuItem(title: "Copy", action: #selector(OfficeMapController.copyText)) 
      menu.menuItems = [copyItem] 

    menu.setTargetRect(CGRectMake(50, 50, 50, 50), inView: longPressView.view!) 
    menu.setMenuVisible(true, animated: true) 


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

    func copyText(sender: UILongPressGestureRecognizer) 
{ 
    let searchlbl = sender.view! as UIView 
    print(searchlbl) 
    //Than Label Value code for Copy 

} 
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool { 
    // You need to only return true for the actions you want, otherwise you get the whole range of 
    // iOS actions. You can see this by just removing the if statement here. 

    if action == #selector(OfficeMapController.copyText) { 

     return true 
    } 
    return false 
} 

FEHLER UNTER

2016-05-20 16:59:40.428 [2732:1548168] -[UIMenuController view]:  unrecognized selector sent to instance 0x155507820 
2016-05-20 16:59:40.429 [2732:1548168] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIMenuController view]: unrecognized selector sent to instance 0x155507820' 
    *** First throw call stack: 
    (0x180c3ae38 0x18029ff80 0x180c41ccc 0x180c3ec74 0x180b3cd1c 0x100183dbc 0x100183f10 0x18634638c 0x18634574c 0x181602628 0x180bf181c 0x180bf14c0 0x180beebd4 0x180b18d10 0x182400088 0x185dedf70 0x10019caa0 0x1806b68b8) 
    libc++abi.dylib: terminating with uncaught exception of type NSException 

Könnte mir jemand helfen, für unten Lösungen, um herauszufinden?

+0

hinzufügen Sie langes Drücken auf webView oder was helfen ?? –

+0

@RahulShirphule, Nein ist eine einfache UIView –

+0

Eigentlich weiß ich nicht, wie Sie von UIView kopieren, weil nach meinem Verständnis können Sie nicht Inhalt von UIView kopieren ... für das müssen Sie Textansicht/Webview ect, die unterstützt werden die Auswahl und Kopierfunktion ..! –

Antwort