This question already has an answer here:
Using UITableviewcell
class for displaying the cell of table list. I want to redirect from one screen to another using "navigationController?.pushViewController
", but it is not supporting in table cell class. So how can i move UIViewcontroller
using pushViewController from table cell.
My code is:
class TableCell: UITableViewCell
{
let storyBoard : UIStoryboard = UIStoryboard(name: "SubMain", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "DetailReport") as! DetailReport
nextViewController.aryOfResultList = aryForCreateJSONResult
cell.inputViewController?.navigationController?.pushViewController(nextViewController, animated: true)
}
But its not working. Please give me the solution of my question
Declare a variable in the cell called
var parent: UIViewController?
. in the parent controller, in the functioncellForRow
,now in the cell you can call
Update if what u want is simply to push the view controller when a cell is taped, u can do it in the parent controller in:
Get the ViewController from helper function :
and then in your custom cell, use
parentViewController.navigationController
You can use this for all
UIView
types.You've to assign
pushViewController
code intotableView didSelectRowAt()
method e.g.You can always navigate using the navigation controller from one view controller to another and table view cell is not a
UIViewController
type, its aUIView
type.You can either create a delegate in custom table view cell and that will confirm the
UIViewController
and implement the cell delegate's method in view controller.or you can navigate to other screen then cell is tapped in table view.