伙计们,我在 Rxswift 中是全新的,有没有办法在 RxSwift 中完成这个场景?
我得到的是这个..但问题是我没有 indexPath
datasource.sectionModels
.asObservable()
.bindTo(tableView.rx.items) { tableView, row, element in
guard let sectionType = SectionType(rawValue: indexPath.section) else { return 0 }
let indexPath = IndexPath(row: row, section: 0)
var itemForIndexPath: SectionViewModel {
return self.datasource.sectionModels.value[indexPath.section]
}
switch sectionType {
case .nickTitle, .nickIfno:
let infoCell = tableView.dequeueReusableCell(
withIdentifier: InfoTableViewCell.name,
for: indexPath
) as! InfoTableViewCell
var datasource: InfoCellDatasourceProtocol = InfoCellNormalState(text: itemForIndexPath.text)
if itemForIndexPath.errorStyle {
datasource = InfoCellErrorState(text: itemForIndexPath.text)
}
infoCell.configureCell(datasource: datasource)
}
这就是我在 RxSwift 中所需要的
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let sectionType = SectionType(rawValue: indexPath.section) else { return UITableViewCell() }
var itemForIndexPath: SectionViewModel {
return self.datasource.sectionModels.value[indexPath.section]
}
switch sectionType {
case .nickTitle, .nickInfo:
let infoCell = tableView.dequeueReusableCell(
withIdentifier: InfoTableViewCell.name,
for: indexPath
) as! InfoTableViewCell
var datasource: InfoCellDatasourceProtocol = InfoCellNormalState(text: itemForIndexPath.text)
if itemForIndexPath.errorStyle {
datasource = InfoCellErrorState(text: itemForIndexPath.text)
}
infoCell.configureCell(datasource: datasource)
return infoCell
数据源片段:
open class RegistrationNickDataSource: NickDatasourceProtocol {
public var error: Variable<ErrorType>?
public var success: Variable<Bool> = Variable(false)
fileprivate let request = ValidateNameRequest()
public var nickHints: Variable<[String]>?
public var sectionModels: Variable<[SectionViewModel]> = Variable([
SectionViewModel(
text: "your_nick_hint".localized,
type: .info,
errorStyle: false
),
SectionViewModel(
text: "your_nick_placeholder".localized,
type: .input,
errorStyle: false
),
SectionViewModel(
text: "your_nick_info".localized,
type: .info,
errorStyle: false
)]
)
感谢您的每一个帮助