意外的标签和tableview发现没有

时间:2017-02-08 07:06:55

标签: ios swift uitableview uilabel

我正在为nib菜单加载leftSlideMenu已成功添加,但是当我设置lbltext或重新加载表格视图时,在展开选项值时意外发现错误为nil。下面是我的代码。

这些是连接的出口

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

此方法位于我的UIView类

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

    }
}

这是UIViewController类的@IBAction

@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
    }
}   

感谢。

1 个答案:

答案 0 :(得分:0)

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

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