AlertView Проблема в iOS 13 Swift 4.2 - PullRequest
0 голосов
/ 25 февраля 2020

Вот мой обобщенный класс c, который я использую повсюду в моем проекте, но он вызывает проблемы на iOS 13, т.е. AlertView, появляющиеся n, автоматически исчезают перед выбором любого параметра.

//var status = false
class AlertClass{//This is shared class
    static let sharedInstance = AlertClass()

    //Show alert
    func alertWindow(title: String, message: String, completion:@escaping (_ result: Bool) -> Void) {
            let alertWindow = UIWindow(frame: UIScreen.main.bounds)
            alertWindow.rootViewController = UIViewController()
            alertWindow.windowLevel = UIWindow.Level.alert + 1

            let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
            let defaultAction1 = UIAlertAction(title: "Yes", style: .destructive, handler: { action in
                completion(true)

            })
            let defaultAction2 = UIAlertAction(title: "No", style: .destructive, handler: { action in
                print("No")
                completion(false)
            })
            alert2.addAction(defaultAction1)
            alert2.addAction(defaultAction2)

            alertWindow.makeKeyAndVisible()

            alertWindow.rootViewController?.present(alert2, animated: true, completion: nil)
    }

    func alertOkWindow(title: String, message: String, completion:@escaping (_ result: Bool) -> Void) {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindow.Level.alert + 1

        let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let defaultAction1 = UIAlertAction(title: "Ok", style: .default, handler: { action in
            completion(true)

        })
        alert2.addAction(defaultAction1)

        alertWindow.makeKeyAndVisible()

        alertWindow.rootViewController?.present(alert2, animated: true, completion: nil)
    }


    func alertDialogWithImage(msg: String, Icon : UIImage?) {
        let alertDialogWithImage = UIWindow(frame: UIScreen.main.bounds)
        alertDialogWithImage.rootViewController = UIViewController()
        alertDialogWithImage.windowLevel = UIWindow.Level.alert + 1
        let alrt = UIAlertController(title:  " ", message: msg, preferredStyle: .alert)

        let cancel = UIAlertAction(title: "Ok", style: .destructive) { (action) in


        }



        alrt.addAction(cancel)

        let subview = (alrt.view.subviews.first?.subviews.first?.subviews.first!)! as UIView

//        subview.backgroundColor = UIColor(red: (145/255.0), green: (200/255.0), blue: (0/255.0), alpha: 1.0)

//        alrt.view.tintColor = UIColor.black
        alrt.view.tintColor = UIColor.red

        let imageView = UIImageView(frame: CGRect(x: 120, y: 10, width: 35, height: 35))

        imageView.image = Icon

        alrt.view.addSubview(imageView)

        alertDialogWithImage.makeKeyAndVisible()
        alertDialogWithImage.rootViewController?.present(alrt, animated: true, completion: nil)
    }

    func alertWith3Actions(title: String, message: String, action1: String, action2: String, action3: String, completion:@escaping (_ result: Bool) -> Void) {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindow.Level.alert + 1

        let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
        let defaultAction1 = UIAlertAction(title: action1, style: .destructive, handler: { action in
            completion(true)

        })
        let defaultAction2 = UIAlertAction(title: action2, style: .destructive, handler: { action in
            print("No")
            completion(false)
        })
        let defaultAction3 = UIAlertAction(title: action3, style: .destructive, handler: { action in
            print("Later")
            completion(false)
        })
        alert2.addAction(defaultAction1)
        alert2.addAction(defaultAction2)
        alert2.addAction(defaultAction3)

        alertWindow.makeKeyAndVisible()

        alertWindow.rootViewController?.present(alert2, animated: true, completion: nil)
    }

    func alertTitleandMessage(title: String, message: String) {
        DispatchQueue.main.async(execute: {
            let alertTitleandMessage = UIWindow(frame: UIScreen.main.bounds)
            alertTitleandMessage.rootViewController = UIViewController()
            alertTitleandMessage.windowLevel = UIWindow.Level.alert + 1

            let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
            let defaultAction2 = UIAlertAction(title: "OK", style: .destructive, handler: { action in
            })
            alert2.addAction(defaultAction2)

            alertTitleandMessage.makeKeyAndVisible()

            alertTitleandMessage.rootViewController?.present(alert2, animated: true, completion: nil)
        })
    }

}

Я изменил свой код, как я определяю эти функции в расширении UIViewController, но после этого я не могу вызвать их в UITableViewCell & UICollectionViewCell. Ваша помощь и руководство будут высоко оценены. Заранее спасибо. Br.

...