Simple UITableView in Swift - unexpectedly found nil

后端 未结 13 1573
旧巷少年郎
旧巷少年郎 2020-12-06 00:38

Pretty simple code:

func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
    return 1
}

func tableView(tableView:UITableView!, numberOfRows         


        
13条回答
  •  感情败类
    2020-12-06 01:25

    Swift 5 In same storyboard two class are there Class A and Class B, Class B contains tableview outlet, when i tried to push Class A to Class B it's crashed and show tableView outlet nil.

    In class A i did navigation like below code.

    let classBObj = ClassB()
    self.navigationController?.pushViewController(classBObj, animated: true)
    

    Then i realised my mistake and used below code and it's work perfectly.

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let classBObj = storyboard.instantiateViewController(withIdentifier: "ClassB") as! ClassB
    self.navigationController?.pushViewController(classBObj, animated: true)
    

提交回复
热议问题