I’m trying to subclass UITextField, but I get this...
# ios
c
I’m trying to subclass UITextField, but I get this error:
Unable to call non-designated initializer as super constructor
. The code I have is:
Copy code
private class Select: UITextField {

    @OverrideInit
    constructor(): super()

    override fun caretRectForPosition(position: UITextPosition): CValue<CGRect> {
        return CGRectMake(x = 0.0, y = 0.0, width = 0.0, height = 0.0)
    }

    override fun selectionRectsForRange(range: UITextRange): List<*> {
        return listOf<Any?>(null)
    }

    override fun canPerformAction(action: COpaquePointer?, withSender: Any?): Boolean {
        return false
    }
}
Anyone know what should I do? I guess I could use
disableDesignatedInitializerChecks
but that doesn’t seem right
n
not sure how to spell this in Kotlin but you should be calling
super(frame: CGRectZero)
, I believe
🙂 1
c
Thanks! I added:
Copy code
UITextField(frame = CGRectZero.readValue())
Let’s see if it works 🙂
r
UITextField(cValue())
should work
c
And what about the override of selectionRectsForRange? The way I was overriding it, it gives me an error about the null
For future reference, if anyone stumbles upon this:
Copy code
override fun selectionRectsForRange(range: UITextRange): List<*> {
        return listOf<UITextSelectionRect>()
    }
👍 1