Swift 3 popup model dialog传递数据

前端之家收集整理的这篇文章主要介绍了Swift 3 popup model dialog传递数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@IBAction func txtPasswordClicked(_ sender: Any) {
        let popupKeyboardVC = storyboard?.instantiateViewController(withIdentifier: "popupKeyboard") as! PopupKeyboardVC
        
        popupKeyboardVC.delegate = self
        //popupKeyboardVC.strSaveText=labelText.text
        
        popupKeyboardVC.modalPresentationStyle = .popover
        if let popoverController = popupKeyboardVC.popoverPresentationController {
            popoverController.sourceView = sender as! UIView
            popoverController.sourceRect = (sender as AnyObject).bounds
            popoverController.permittedArrowDirections = .any
            popoverController.delegate = self
        }
        present(popupKeyboardVC,animated: true,completion: nil)
    }
    
    func saveText(strText: NSString) {
        txtPassword.text = strText as String;
    }
    
    // MARK: - UIPopoverPresentationControllerDelegate
    func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle {
        return .fullScreen
    }
    
    func presentationController(controller: UIPresentationController!,viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController! {
        return UINavigationController(rootViewController: controller.presentedViewController)
    }


弹出的controller:

protocol SavingViewControllerDelegate
{
func saveText( strText : NSString)
}

class PopupKeyboardVC: UIViewController,UITextFieldDelegate{
override func viewDidLoad() {

}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
@IBOutlet weak var btnDone: UIButton!
var delegate : SavingViewControllerDelegate?

@IBAction func btnDoneClick(_ sender: Any) {
    if (self.delegate) != nil
    {
        delegate?.saveText(strText: "abc")
    }
    self.dismiss(animated: true,completion: nil)
}
}

猜你在找的Swift相关文章