6

Simply put, I have a slide navigation view controller in my app with a back table VC and a front table VC. A selected cell in the back table VC is supposed to segue to the front table VC (embedded in a navigation VC). To illustrate, here are the isolated pre-change settings and code with it working properly:

enter image description here enter image description here enter image description here

Here is the simplified working code in my back table VC's cellForRowAtIndexPath method:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let navigationCell = tableView.dequeueReusableCellWithIdentifier("NavigationCell", forIndexPath: indexPath) as UITableViewCell
    return navigationCell
}

Ok, onto the fun part. All I want is to replace the default UITableViewCell shown above with one of my custom cells in a Xib file. Now I'll illustrate what I modified. First, here's my Xib cell in my NavigationCell.xib file. Nothing special.

enter image description here enter image description here

My NavigationCell class code is simply

import UIKit

class NavigationCell: UITableViewCell {
    @IBOutlet var nameLabel: UILabel!
}

Finally, I modified my code in my back table VC to register the Xib and dequeue the custom cell:

override func viewDidLoad() {
    super.viewDidLoad()
    let navigationCellNib = UINib(nibName: "NavigationCell", bundle: nil)
    tableView.registerNib(navigationCellNib, forCellReuseIdentifier: "NavigationCell")
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let navigationCell = tableView.dequeueReusableCellWithIdentifier("NavigationCell", forIndexPath: indexPath) as! NavigationCell
    return navigationCell
}

All other code and specifications remain the same. The storyboard segue for the new custom cell is still from the class SWRevealViewControllerSeguePushController as shown in the first screenshot for this question. I simply swapped out the default UITableViewCell with my custom Xib cell.

This modification was enough to stop the segue from occurring. With this modification, after I build and run when I slide out the back table VC navigation menu and select one of my custom navigation cells (which display properly), it doesn't trigger any segue. Any thoughts?

Aaron
  • 6,466
  • 7
  • 37
  • 75
  • I've used SWRevealController before and this stuff gets tricky. Have you tried making the segue a setController instead of pushController? – NSGangster Nov 19 '15 at 22:40
  • I have switched it back and forth to no avail. When I tap the navigation cell it highlights in the default light grey and triggers the `didSelectRowAtIndexPath` method but that's as far as it goes. – Aaron Nov 19 '15 at 22:54
  • Here's a tutorial I used when I was first messing around with SWRevealController http://www.appcoda.com/ios-programming-sidebar-navigation-menu/ You have most of it setup go to the section titled implementing menu Item selection. it appears You need a segue identifier and prepare for segue method. Also make sure you have the proper sw_front, sw_rear segue identifiers. This is a good tutorial. – NSGangster Nov 19 '15 at 23:07
  • Thanks for the help @MatthewLawrenceBailey, unfortunately I have all of those things implemented. The sw_front, sw_rear, and prepareForSegue. I left those code samples out of this question because everything was working before and I only am showing what was changed to make it not work. My navigation cell is not even triggering the prepareForSegue method. – Aaron Nov 19 '15 at 23:15
  • From the top right pictures it shows you have no segue identifier set for the segue not being called. This could cause the prepare for segue not to trigger. Set it to anything eg. 'segueIdentifier' and then implement `if ([segue.identifier isEqualToString:@"segueIdentifier"])` in the prepareForSegue in SWRevealViewController.m its just a little further down in the tutorial from the setting the other segues – NSGangster Nov 19 '15 at 23:24
  • Unfortunately that didn't work :-/. I have the sw_front and sw_rear identifiers for the other segues but this segue identifier was blank before when it was working properly. Also the methods shown in that tutorial for the `prepareForSegue` have been deprecated in the framework – Aaron Nov 19 '15 at 23:36
  • do you have a sw_right identifier? I think It goes from the swRevealController to the view your pushing to. – NSGangster Nov 19 '15 at 23:38
  • I didn't have one when it was working. Here's what I have for segues http://imgur.com/a/AnV4a – Aaron Nov 19 '15 at 23:48
  • Have you tried taking out the registerNib lines in viewDidLoad? I'm pretty sure you do not have to register nib since you use the cellReuseIdentifier of and its on storyboard. – NSGangster Nov 20 '15 at 00:06
  • That seems to get me one step closer! If I comment everything out in my `cellForRowAtIndexPath` it works and I have empty navigations cells that segue properly. However, when I try to set the custom Xib outlets in `cellForRowAtIndexPath` then it crashes saying it "unexpectedly found nil". Here's another image for context http://imgur.com/a/C3IUm – Aaron Nov 20 '15 at 00:24

1 Answers1

4

I'm an idiot. I had to perform the segue programmatically in didSelectRowAtIndexPath.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("MySegue", sender: self)
}
Aaron
  • 6,466
  • 7
  • 37
  • 75