0

I'm working with swift 2.2 and xcode 7.3 . I am trying to load a table view from another tableview when a row gets clicked . In

didSelectRowAtIndexPath

of the first table View , I create an instance of the other table view class and call it using the pushViewController . But the table view doesn't get loaded and screen remains the same. My code is

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    NSLog("It did enter the didselectRowAtIndexPath")
    if (indexPath.section == 0){
        let enrolledView = DetailsViewController()
        navigationController?.pushViewController(enrolledView, animated: true)
    }

    if (indexPath.section == 1){
        let appcatalog = AppCatalogViewController()
        navigationController?.pushViewController(appcatalog, animated: true)
    }

    if (indexPath.section == 2){
        let support = supportViewController()
        navigationController?.pushViewController(support, animated: true)
    }


}

Note : "It did enter the didselectRowAtIndexPath" gets printed in the log . SO Kindly let me know if there is something that am not doing correctly .

AnxiousMan
  • 578
  • 2
  • 8
  • 25

2 Answers2

0

Could you give us a bit more of your code?

For example how have you embedded your class in a navigation controller?

Because if nothing appears it is probably due to the fact that navigationController is nil

Nicolas Rosa
  • 121
  • 2
0

I think you have two mistakes in your code.

The first one:

You haven't embedded your controller into a UINavigation controller.

The second One:

You are not initiating your view controller before your could move onto it.First assign a storyboard identifier to each of your view controller. So change your code as:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
NSLog("It did enter the didselectRowAtIndexPath")
if (indexPath.section == 0){
    let enrolledView = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your DetailsViewController")
    navigationController?.pushViewController(enrolledView, animated: true)
}

if (indexPath.section == 1){
    let appcatalog = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your AppCatalogViewController")
    navigationController?.pushViewController(appcatalog, animated: true)
}

if (indexPath.section == 2){
    let support = self.storyboard?.instantiateViewControllerWithIdentifier("identifier of your supportViewController")
    navigationController?.pushViewController(support, animated: true)
}


}
Amrit Sidhu
  • 1,870
  • 1
  • 18
  • 32
  • Yes . I haven't embed it ..and would changing the code like you have said will fix that as well ? – AnxiousMan Apr 04 '16 at 09:47
  • I just read above that you are not using the storyboard? Are you using XIB's? – Amrit Sidhu Apr 04 '16 at 09:49
  • If you are using XIB's then load the nib file as let enrolledViewArray = NSBundle.mainBundle().loadNibNamed("myXib", owner: self, options: nil) let enrolledView = enrolledViewArray[0] navigationController?.pushViewController(enrolledView, animated: true) – Amrit Sidhu Apr 04 '16 at 09:51
  • I ain't using XIB's i guess .. the point is , I have created individual table view controllers and want to load one when a row in another is clicked . And I ain't sure of how to do it . So Can you please instruct me things that needs to be done to do that when am not using storyboards ? – AnxiousMan Apr 04 '16 at 09:53
  • Have you created a tableViewController programatically?? – Amrit Sidhu Apr 04 '16 at 10:01
  • Can you show the code how you are creating it programatically? – Amrit Sidhu Apr 04 '16 at 10:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/108165/discussion-between-maneesh-sharma-and-amrit-sidhu). – AnxiousMan Apr 04 '16 at 10:06