简体   繁体   中英

Unexpectedly label and tableview found nil

I am loading a nib for leftSlideMenu menu is added successfully but when I am setting lbltext or reloading table view getting error unexpectedly found nil while unwrapping an option value. below is my code.

these are outlets which are connected

@IBOutlet weak var lblUserName: UILabel!
@IBOutlet weak var lblUserEmployee: UILabel!

This method is in my UIView class

func prepareScreenWithView(navigationController: UINavigationController, viewSize: UIView) {

    nibView = Bundle.main.loadNibNamed("LeftSlideMenu", owner: self, options: nil)?[0] as! UIView
    navController = navigationController
    nibView.tag = 100
    var tempRect = nibView.frame
    print(tempRect)

    lblUserEmployee.text = "Employee Name" // here i am getting the error.


    tempRect =  CGRect(x: -200, y: 0, width: tempRect.width, height: UIScreen.main.bounds.height)
    viewSize.addSubview(self.nibView)
    lblUserEmployee.text = " "
    UIView.transition(with: self.nibView, duration: 2, options: [.beginFromCurrentState], animations: {
        tempRect.origin.x +=  200
        self.nibView.frame = tempRect

    }) { (success) in

    }
}

This is the @IBAction which of UIViewController class

@IBAction func onClick_Hamberger(_ sender: UIButton) {

    if !isShowingMenu {

        instanceOfLeftSlideMenu.prepareScreenWithView(navigationController: self.navigationController!, viewSize: self.view)
        btnHamburgerMenu.frame.origin.x += 200
        isShowingMenu = true
    } else {

        instanceOfLeftSlideMenu.hideSlideMenu(navigationController: self.navigationController!, viewSize: self.view)
        btnHamburgerMenu.frame.origin.x -= 200
        isShowingMenu = false
    }
}   

Thanks.

尝试为Bundle.main.loadNibNamed的参数所有者传递“ nil ”。

nibView = Bundle.main.loadNibNamed("LeftSlideMenu", owner: nil, options: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM