【发布时间】:2017-03-13 13:23:57
【问题描述】:
我的 Storyboard 中有一个基本的导航设置:一个原版的 UIViewController 嵌入在一个 UINavigationController 中。在我的主 VC 中,我有两个按钮,每个按钮都连接到 UIViewController 子类:LabelledVC。在子类的 viewDidAppear(_:) 方法中,我将导航项的 titleView 设置为自定义图像:
class LabelledVC: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let logoImage = UIImage(named: "apple")
let logo = UIImageView(image: logoImage)
logo.contentMode = .scaleAspectFit
logo.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
navigationItem.titleView = logo
}
}
由于某种原因,LabelledVC 的 viewDidAppear(_:) 方法在应用加载时被调用(在它被推送到导航堆栈之前),这对我来说没有任何意义。你可以找到项目here。
【问题讨论】:
-
在您的项目中,您的 Viewcontroller 是 LabelledVC 的子类。
标签: ios swift uiviewcontroller swift3 uinavigationcontroller