Eureka: Spaces not visible in right-aligned rows when editing text

Created on 15 May 2016  路  6Comments  路  Source: xmartlabs/Eureka

Now this isn't a issue unique to Eureka, but perhaps there should be a default or an easy way to toggle this behavior for right-aligned text fields? It's definitely off-putting (to me) when typing.

http://stackoverflow.com/questions/19569688/right-aligned-uitextfield-spacebar-does-not-advance-cursor-in-ios-7/22512184#22512184

http://stackoverflow.com/questions/22232884/space-at-end-of-text-not-visible-in-right-aligned-uitextfield

I'm doing this which works for now (in reality should put normal spaces back when finished editing). Is there a better/cleaner way?

class MyViewController: FormViewController {
    func replaceNormalSpacesWithNonBreakingSpaces(textField : UITextField) {
        textField.text = textField.text?.stringByReplacingOccurrencesOfString(" ", withString: "\u{00a0}")
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        form +++ Section("MySection")
        <<< TextRow("title") {
             $0.title = "Title"
             $0.placeholder = "Title"          
        }.cellSetup {cell, row in
             cell.textField.addTarget(self, action: #selector(MyViewController.replaceNormalSpacesWithNonBreakingSpaces), forControlEvents: .EditingChanged)
        }
...
enhancement iOS issue issue

Most helpful comment

Thanks for the workaround, @heptal. I ended up doing the following to get the desired behavior for all my UITextFields:

// Configure text rows to make spaces visible on edit.
TextRow.defaultCellSetup = { cell, row in
    cell.textField.addTarget(self, action: #selector(FormHelper.replaceNormalSpacesWithNonBreakingSpaces(_:)), forControlEvents: .EditingChanged)
    cell.textField.addTarget(self, action: #selector(FormHelper.replaceNonBreakingSpacesWithNormalSpaces(_:)), forControlEvents: .EditingDidEnd)
}

Maybe that's as close to a built-in way as it gets?

All 6 comments

Thanks for the workaround, @heptal. I ended up doing the following to get the desired behavior for all my UITextFields:

// Configure text rows to make spaces visible on edit.
TextRow.defaultCellSetup = { cell, row in
    cell.textField.addTarget(self, action: #selector(FormHelper.replaceNormalSpacesWithNonBreakingSpaces(_:)), forControlEvents: .EditingChanged)
    cell.textField.addTarget(self, action: #selector(FormHelper.replaceNonBreakingSpacesWithNormalSpaces(_:)), forControlEvents: .EditingDidEnd)
}

Maybe that's as close to a built-in way as it gets?

Yep, would also appreciate an built-in solution for that. @heptal Thanks for the workaround!

@heptal nice workaround.

Thanks guys for this workaround - here's an updated version for Swift3.
Call EurekaWhitespaceWorkaround.configureTextCells() to use it.
https://gist.github.com/hannesoid/ed78904e33a362889d2bd38f2f09ec3b

This seems to be a iOS issue so we will not add any workaround in Eureka. Everyone facing the issue can easily add the workaround.

Regards

@lognaturel : can you please show FormHelper class ? Thank you

Was this page helpful?
0 / 5 - 0 ratings