<分区>
我意识到有人问过关于 fatal error 和解包选项的类似问题,但在这种情况下,我添加到我的代码中的唯一东西是两个 socket (我已经检查了它们的连接),现在我在一些地方遇到了错误以前没有引发错误。
我的代码运行良好,然后我添加了两个容器 View ,它崩溃并提示:“ fatal error :在展开可选值时意外发现 nil”,但我不知道可选值在哪里。它说它与一个名为 segmentBackground 的 UIview 有关,但在我添加容器 View 之前它没有引发任何错误。
感谢您提前提供的帮助。
这是我的代码:
class DetailMosaicViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// Properties
var mosaic: String?
var overviewBottomBorder: UIView?
var modelsBottomBorder: UIView?
var sectionTitles = [String]() {
didSet {
profileTableView.reloadData()
}
}
var mainText = [String]() {
didSet {
profileTableView.reloadData()
}
}
// Outlets
@IBOutlet weak var segmentBackground: UIView!
@IBOutlet weak var profileTableView: UITableView!
@IBOutlet weak var profileModelsSegment: UISegmentedControl!
@IBOutlet weak var modelsContainerView: UIView!
@IBOutlet weak var profileContainerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
if let mosaic = mosaic {
navigationItem.title = mosaic
}
self.navigationController?.navigationBar.tintColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0)
configureSegmentController()
configureText()
// Configures TableView
profileTableView.delegate = self
profileTableView.dataSource = self
profileTableView.separatorColor = UIColor.black
profileTableView.estimatedRowHeight = 140
profileTableView.rowHeight = UITableViewAutomaticDimension
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func configureSegmentController() {
segmentBackground.backgroundColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0)
profileModelsSegment.center = segmentBackground.center
profileModelsSegment.setTitle("Profile", forSegmentAt: 0)
profileModelsSegment.setTitle("Models", forSegmentAt: 1)
profileModelsSegment.tintColor = UIColor.white
profileModelsSegment.selectedSegmentIndex = 0
}
func configureText() {
// make request to firebase, store, and assign to tableView
sectionTitles = ["Description", "Business Models", "Moats", "Competition", "Unit Economics"]
}
@IBAction func switchAction(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.5, animations: {
self.profileTableView.alpha = 1
self.modelsContainerView.alpha = 0
})
} else {
UIView.animate(withDuration: 0.5, animations: {
self.profileTableView.alpha = 0
self.modelsContainerView.alpha = 1
})
}
}
// TableView Datasource
// Customizes Section Titles
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
// Makes Background White
let cell = tableView.dequeueReusableCell(withIdentifier: "customHeader") as UITableViewCell!
cell?.textLabel?.text = sectionTitles[section]
cell?.contentView.backgroundColor = UIColor.white
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return sectionTitles.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//configure cell
let cell = tableView.dequeueReusableCell(withIdentifier: "profileCell", for: indexPath) as! ProfileCell
cell.mainSectionText.text = "Box (company) Box (formerly Box.net), based in Redwood City, California, is a cloud content management and file sharing service for businesses. The company uses a freemium business model to provide cloud storage and file hosting for personal accounts and businesses."
return cell
}
这是错误信息:
我的 socket 连接: