Skip to content

textView in tableView cell #424

@tominisx-12

Description

@tominisx-12

Hi, I'm using RxTableViewSectionedAnimatedDataSource to create table view. One of the cells have textview. I subscribe to changes in textview text as follows:

        textView.rx.text.orEmpty
            .subscribe(onNext: { [weak self] text in
                self.viewModel.updateNote(note: text)
            })
            .disposed(by: disposeBag)

Then, I modify my textview text data in viewModel:

var subject = BehaviorRelay<[EventSectionModel]>.init(value: [])

    func updateNote(note: String) {
        var newSections = subject.value
        if let sectionIndex = newSections.firstIndex(where: { section in
            section.items.contains(where: { item in
                if case let .typeC(info) = item, info.noteName == noteName {
                    return true
                } else {
                    return false
                }
            })
        }), let itemIndex = newSections[sectionIndex].items.firstIndex(where: { item in
            if case let .typeC(info) = item, info.noteName == noteName {
                return true
            } else {
                return false
            }
        }) {
            var updatedItem = newSections[sectionIndex].items[itemIndex]
            if case .typeC(var info) = newSections[sectionIndex].items[itemIndex] {
                info.note = note
                updatedItem = .typeC(info)
                newSections[sectionIndex].items[itemIndex] = updatedItem
                subject.accept(newSections)
            }
        } else {
            print("No matching item found")
        }
    }

The problem is, when I call line bellow my cell with textview is reloaded and it causes keyboard to dismiss.
subject.accept(newSections)

So every time user types a letter, it dismisses keyboard. How to overcome this?

Thanks a lot! Any help/tips are welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions