【发布时间】:2015-10-30 02:17:51
【问题描述】:
在我的应用程序中,我有一个自定义 UIViewController,它有一个相应的 XIB 文件。我在 XIB 文件中创建了几个按钮和标签,并为自定义 UIViewcontroller 创建了出口。然后我通过通常的方式将此视图控制器推送到导航堆栈上:
let challengeDetails = ChallengeDetails()
self.navigationController!.pushViewController(challengeDetails, animated: true)
我知道视图控制器正在被压入堆栈,因为我将其视图的背景颜色设置为红色,而我得到的是一个空白的红色视图。我不明白为什么我没有看到我在 XIB 文件中创建的标签和按钮。
我已经检查了一些常见的事情:文件的所有者设置为我的自定义类。 xib 的视图连接到视图控制器(在 Outlets 中)。
当我创建项目时,我选择了“选项卡式应用程序”,它附带了一个故事板。但是,当我创建 XIB 文件时,我只需在创建新的视图控制器子类时选中复选框即可。 XIB 是否必须连接到故事板才能工作?
任何帮助将不胜感激。如果有帮助,这里是自定义类:
import UIKit
class ChallengeDetails: UIViewController {
// Outlets from xib file.
@IBOutlet weak var challengeDescriptionTextView: UITextView!
@IBOutlet weak var challengeTitleLabel: UILabel!
@IBAction func browseTitlesButton(sender: UIButton) {
browseTitlesInChallenge()
}
@IBAction func acceptChallengeButton(sender: UIButton) {
acceptThisChallenge()
}
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.redColor()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func browseTitlesInChallenge() {
}
func acceptThisChallenge() {
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
【问题讨论】:
标签: ios iphone swift uiviewcontroller xib