简体   繁体   中英

How to call function to change viewController from UITableViewCell class in Swift?

I need call a function from a UITableViewCell class to change viewController, but I get: "fatal error: unexpectedly found nil while unwrapping an Optional value"

 class Custom: UITableViewCell{
      var myClass: MyClass!
       myClass = MyClass()
        myClass.call()
}

 class MyClass: UIViewController {
     func call (){
         let nextView =  self.storyboard!.instantiateViewControllerWithIdentifier("view") as    MyViewController

    self.navigationController!.pushViewController(nextView, animated: true)
     } 
 }

How can do this correctly?

Thanks!

You can't call function like that you must have to definw some method and than call that function! for example

class Custom: UITableViewCell{
  var myClass: MyClass=MyClass()
 func callMethod(){

 myClass.call()
}
}

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