我正在为带有菜单的应用编写代码,出于某种奇怪的原因,Xcode给了我一个零错误。感谢所有帮助。
//
// ViewController.swift
// Menu
//
// Created by Programmer on 8/1/17.
// Copyright © 2017 Programmer. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var LeadingConstr1: NSLayoutConstraint!
@IBOutlet weak var MenuView1: UIView!
@IBOutlet weak var LeadingConstr2: NSLayoutConstraint!
@IBOutlet weak var MenuView2: UIView!
var menushowing1 = false;
var menushowing2 = false;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
MenuView1.layer.shadowOpacity = 1
MenuView1.layer.shadowRadius = 6
MenuView2.layer.shadowOpacity = 1
MenuView2.layer.shadowRadius = 6
}
@IBAction func MenuBtn(_ sender: Any) {
if (menushowing1) {
LeadingConstr1.constant = -140
}
else {
LeadingConstr1.constant = 0
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
view.layoutIfNeeded()
}
menushowing1 = !menushowing1
}
@IBAction func MenuBtn2(_ sender: Any) {
if (menushowing2) {
LeadingConstr2.constant = -140
}
else {
LeadingConstr2.constant = 0
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
})
view.layoutIfNeeded()
}
menushowing2 = !menushowing2
}
}
以下是我遇到的错误:
致命错误:在展开Optional值时意外发现nil 2017-08-03 07:18:40.647621-0400菜单[383:53946]致命错误: 在解包一个Optional值(lldb) -
时意外地发现了nil
答案 0 :(得分:0)
您有一些与任何Menu
无关的插座@IBOutlet Menu
。从XIB / Storyboard中删除该连接,或在视图控制器中添加该变量。