iosswiftuiviewinputaccessoryview

How to prevent inputAccessoryView of a view controller from being shown when an alert is presented?


I have a custom UIViewController in which I have overridden inputAccessoryView to return a view as follows-

extension LoginViewController {
    override var inputAccessoryView: UIView? {
        CustomToolbar()
    }
}

The inputAccessoryView is shown when an UIAlertController is presented by the view controller.

Can anyone point out how to prevent inputAccessoryView from being shown when an alert is presented?


Solution

  • You can add a check in inputAccessoryView returning logic , and return nil while the alert controller is presented.

    extension LoginViewController {
        override var inputAccessoryView: UIView? {
             if let p = presentedViewController, p.isKind(of: UIAlertController.self) {
                    return nil
                }
            CustomToolbar()
         }
    }