https://kotlinlang.org logo
#ios
Title
# ios
c

Christian Sousa

03/17/2020, 12:23 PM
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

Nikolay Kasyanov

03/17/2020, 12:58 PM
not sure how to spell this in Kotlin but you should be calling
super(frame: CGRectZero)
, I believe
🙂 1
c

Christian Sousa

03/17/2020, 12:59 PM
Thanks! I added:
Copy code
UITextField(frame = CGRectZero.readValue())
Let’s see if it works 🙂
r

ribesg

03/17/2020, 1:04 PM
UITextField(cValue())
should work
c

Christian Sousa

03/17/2020, 1:05 PM
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
4 Views