我正在使用 VIP Clean 创建一个应用程序,但在 LoginRouter 上调用 HomeViewController 时遇到问题。
我尝试了几种方法,实例化 homeviewcontroller 并传递 HomeViewController 初始化信息,如下所示:let homeViewController = HomeViewController(interactor: HomeInteractor(repository: HomeRepository(), user: user), router: HomeRouter(navigationController: navigationController), presenter: HomePresenter())
我收到了同样的信息,我不知道如何解决它......
登录路由器:
import UIKit
@objc protocol LoginRouting{
func routeToHome(login:LoginViewController, user: UserRealm)
}
protocol LoginDataPassing{
var dataStore: LoginDataStore? { get }
}
class LoginRouter: NSObject, LoginRouting {
//MARK: - Navigation init
weak var viewController: LoginViewController?
var dataStore: LoginDataStore?
var navigationController = UIViewController()
init(navigationController: UIViewController){
self.navigationController = navigationController
}
//MARK: - Routing and Navigations
func routeToHome(login: LoginViewController, user: UserRealm) {
login.dismiss(animated: true, completion: nil)
let home =
UIStoryboard(name:"Main",bundle:nil).instantiateViewController(identifier:
"HomeViewController")
UIApplication.topViewController()?.present(home, animated: true, completion: nil)
}
}
主视图控制器:
import UIKit
protocol HomeDisplayLogic: class{
func displaySomething(viewModel: Home.ViewModel)
}
class HomeViewController: UIViewController, HomeDisplayLogic {
@IBOutlet weak var usernameLb: UILabel!
@IBOutlet weak var userAccontLb: UILabel!
@IBOutlet weak var userBalance: UILabel!
@IBOutlet weak var tableview: UITableView!
var router: HomeRouter?
private var interector: HomeInteractor
private var presenter: HomePresenter
private var tableViewDataSource: HomeDataSource?
init(interactor: HomeInteractor, router: HomeRouter, presenter: HomePresenter) {
self.interector = interactor
self.interector.presenter = presenter
self.presenter = presenter
self.router = router
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - View lifecycle
override func viewDidLoad() {
populateInformations()
setupView()
}
private func setupView() {
presenter.viewController = self
HomeDataSource.setupHome(tableView: tableview)
tableViewDataSource = HomeDataSource(presenter: presenter)
tableview.dataSource = tableViewDataSource
tableview.delegate = tableViewDataSource
}
// MARK: - PopulateInformations
func populateInformations(){
let request = Home.Request(userId: interector.user.userId ?? "1.0")
interector.getInfoStatements(request: request)
}
func displaySomething(viewModel: Home.ViewModel) {
}
}
当我打电话回家时,我收到以下消息:Fatal error: init(coder:) has not been implemented: file
有人可以向我解释什么是错误的,或者如何正确地将信息从一个视图控制器传递到另一个视图控制器?