gpt4 book ai didi

ios - 如何在 RxSwift 中实现 shouldChangeText

转载 作者:可可西里 更新时间:2023-11-01 01:07:51 25 4
gpt4 key购买 nike

有没有办法以 RxSwift 的方式实现 shouldChangeTextIn UITextView 的委托(delegate)方法?我的目标是限制用户的文本输入。我只有这个:

    self.textView.rx.text
.orEmpty
.scan("") { (previous, new) -> String in
return new.count > 254 ? previous : new
}
.bind(to: self.viewModel.notes)
.disposed(by: self.disposeBag)

这是为了数据,但我不知道如何防止在 254 计数后进一步输入。

我还找到了 RxTextViewDelegateProxy 但我也不确定如何使用它。

let rxTVDelegateProxy = RxTextViewDelegateProxy(textView: self.textView)

最佳答案

试试这个:

       textView.rx.text.orEmpty
.scan("") { (previous, new) -> String in

return new.count < 254 ? new : previous ?? String(new.prefix(254))
}
.bind(to: textView.rx.text)
.disposed(by: disposeBag)

关于ios - 如何在 RxSwift 中实现 shouldChangeText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54034446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com