Textfield works on simulator but not on device

let categoryField: UITextField = {
  let field = UITextField()
  field.layer.borderWidth = 0.5
  field.layer.borderColor = UIColor.gray.withAlphaComponent(0.5).cgColor
  field.layer.cornerRadius = 5
  field.textAlignment = .center
  field.selectedTextRange = nil
  field.placeholder = "Enter Title"
  field.heightAnchor.constraint(equalToConstant: 50).isActive = true
  field.translatesAutoresizingMaskIntoConstraints = false
  field.autocorrectionType = .no
  field.autocapitalizationType = .words
  return field
}()


Which is used below, inside of a viewDidLoad method in a viewController.


let stackView = UIStackView(arrangedSubviews: [
  categoryField,
  UIView()
])
stackView.isUserInteractionEnabled = true
stackView.axis = .vertical
stackView.alignment = .fill
stackView.spacing = 8


It works on Simulator, but when I take the code to a device it doesn't work at all. I've used the same code in other apps and they worked fine. Any thoughts on why it won't work in this?

Please move the question to SwiftUI.


when I take the code to a device it doesn't work at all.

What do you get:

- does it crash ?

- do you get something on screen ?

- does interction not work

- …


And provide context as well:

Which version of iOS in simulator ?

Which version of iOS on device ?

Which version of XCode ?


Please be specific. It doesn't work does not mean a lot (in order to help).

First off this is not a SwiftUI Framework issue, its a UIKit issue. So it would not be prudent to move it to mix with swiftui framework mess.


What I mean by it doesn't work on device is it won't let you enter text or even activate keyboard.


iPhone 11 13.3.1 (yes i know there is an update out, can't update since I don't have access to Wifi until friday.)

Simulator Version 11.4 (921.9)

XCode 11.4 (11E146)

Application Target 13.0


Other possibly discories, I took the exact view controller and placed it in a brand new app with nothing else in it and it worked on both device and simulator. The app it was contained in uses PDFKit which has previouly broken the UIStackView buttons. Even while its in another viewcontroller.


I looked at the view that will show you a visual represntation of the z-axis of the application, that didn't tell me anything was blocking access to it.

I found the function that was causing the issue on the phone, however it still allows you to activate the keyboard on the simulator. I don't even know why I had this in the app, but its been removed and not the app works the way expected. I placed this in a sample project and replicated the issue.


extension UIView {
    override open func becomeFirstResponder() -> Bool {
        return true
    }
}
Textfield works on simulator but not on device
 
 
Q