当我从一个屏幕切换到另一个屏幕时,我得到一个黑屏,我不知道为什么
控制器:
class AddContactsController: UIViewController {
// MARK: - Constants
private enum Constants {
static let textField = "nameTextCell"
static let datePicker = "datePicker"
static let pickerView = "pickerView"
static let textViewNotes = "textViewNotes"
static let alertOk = "OK"
static let alertQuestion = "It seems you made a mistake"
static let navigationTitle = "Create"
}
// MARK: - AddPresenter
var presenter: AddListPresenter?
func instantiate() -> UIViewController {
let vc = AddContactsController()
let presenter = AddListPresenter()
vc.presenter = presenter
return vc
}
主讲人:
class AddListPresenter {
weak var view: AddListController?
private var contact: Contact
init(contact: Contact? = nil) {
self.contact = contact ?? .init(
name: "",
surname: "",
middleName: "",
phone: "",
email: "",
date: "",
sex: "",
notes: ""
)
}
private var saveHieght: CGFloat = 0
如何避免这种情况?我不想将演示者声明转换为viewDidLoad
1条答案
按热度按时间zyfwsgd61#
当你通过直接调用视图控制器的初始化器来创建视图控制器时(例如
AddContactsController()
),它的内容视图不会像从故事板或nibfile那样自动创建。如果你在代码中创建UI,你需要向我们展示你的
loadView()
方法。这是你创建视图层次结构的代码所在。除非你已经实现了
loadView()
,否则你不会看到任何内容视图,并且会看到一个完全像你描述的那样的黑屏。您还需要显示调用
instantiate()
方法的代码,以及如何处理返回的视图控制器示例。