Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textView in tableView cell #424

Open
tominisx-12 opened this issue May 2, 2023 · 0 comments
Open

textView in tableView cell #424

tominisx-12 opened this issue May 2, 2023 · 0 comments

Comments

@tominisx-12
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant