在我的应用程序崩溃之前,这就是我设置我的视图控制器的方式,它运行良好:
var form: MainFormViewController?
func addTapped() {
// form?.delegate = self
form = MainFormViewController(collectionViewLayout: UICollectionViewFlowLayout())
let nav = UINavigationController(rootViewController: form!)
navigationController?.present(nav, animated: true)
}
我重申了这一点,所以看起来很不寻常,但你明白了。
但是现在我想立即实例化这个视图控制器。所以我添加了这段代码并获得了BAD ACCESS
代码2。
此外,当我在我的集合视图上尝试super.init(layout)
时,我也获得了错误的访问权限。我不知道这两个事件是否相关。
MainFormViewController.swift 没有init
。我在viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.brown
// navigationController?.navigationBar.barTintColor = #colorLiteral(red: 0.1176, green: 0.251, blue: 0.4863, alpha: 1)
navigationController?.navigationBar.backgroundColor = #colorLiteral(red: 0.1176, green: 0.251, blue: 0.4863, alpha: 1)
let stopButton = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(stopTapped))
stopButton.tintColor = .white
navigationItem.setLeftBarButton(stopButton, animated: true)
collectionView?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: stockCellId)
collectionView?.register(MainFormCollectionViewCell.self, forCellWithReuseIdentifier: formCellId)
navigationController?.navigationBar.isHidden = false
}
我没有使用故事板
呃我想我的所有init
都需要UICollectionViewController
个。这似乎是问题,对吗?