没有足够的代码来找出您的问题可能是什么。以下是我使用我的Cause_Logic_Effect 库的方法。
import Cause_Logic_Effect
import RxCocoa
import RxSwift
import UIKit
extension FirstView {
func connect() {
Observable.just([
Kinder(name: "Ben"),
Kinder(name: "Mia"),
Kinder(name: "Leon"),
Kinder(name: "Emma")
])
.bind(to: tableView.rx.items(cellIdentifier: "Cell")) { _, kinder, cell in
if #available(iOS 14.0, *) {
var configuration = cell.defaultContentConfiguration()
configuration.text = kinder.name
cell.contentConfiguration = configuration
}
else {
cell.textLabel?.text = kinder.name
}
}
.disposed(by: disposeBag)
// when the user selects a cell, load its Kinder into a newly created
// SecondView and push it onto the navigation stack
tableView.rx.modelSelected(Kinder.self)
.bind(onNext: pushScene(on: navigationController!, animated: true) { kinder in
SecondView().scene { $0.connect(kinder: kinder) }
})
.disposed(by: disposeBag)
}
}
extension SecondView {
func connect(kinder: Kinder) -> Observable<Never> {
// use the Kinder
title = kinder.name
// this controller doesn't send any info back to its parent.
return .never()
}
}
// The view controllers.
final class FirstView: UIViewController {
var tableView: UITableView!
let disposeBag = DisposeBag()
override func loadView() {
super.loadView()
title = "Main"
tableView = UITableView(frame: view.bounds)
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
view.addSubview(tableView)
}
}
final class SecondView: UIViewController {
override func loadView() {
super.loadView()
view.backgroundColor = .white
}
}
// The models
struct Kinder {
let name: String
}
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
// Create a FirstView, configure it with a connector, wrap it in a
// navigation controller and make that the root.
window?.rootViewController = UINavigationController(rootViewController: FirstView().configure { $0.connect() })
window?.makeKeyAndVisible()
return true
}
}