I created a custom cell for my table view in the side menu/navigation drawer and for the most part everything seems to be working fine, but when I select one of the rows (which takes me to another ViewController), then come back from the subsequent table view via the nav drawer, the cell is still gets diselected. For example: When i select A from the side menu table view i am taken to AViewController, when i select B i am taken to BViewController. So basically when i select A and come back to the side menu A should remain highlighted. How can i do that. Code :
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! slideMenuIconTableViewCell
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
switch indexPath.row {
case 0:
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("MyCartViewController")
sideMenuViewController?.contentViewController = UINavigationController(rootViewController: viewController)
sideMenuViewController?.hideMenuViewController()
break
case 1:
let nextViewController:ProductListingViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ProductListingViewController") as! ProductListingViewController
nextViewController.productID = "1"
nextViewController.navigationTitle = "Tables"
sideMenuViewController?.contentViewController = UINavigationController(rootViewController: nextViewController)
sideMenuViewController?.hideMenuViewController()
break
case 2:
let nextViewController:ProductListingViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ProductListingViewController") as! ProductListingViewController
nextViewController.productID = "3"
nextViewController.navigationTitle = "Sofas"
sideMenuViewController?.contentViewController = UINavigationController(rootViewController: nextViewController)
sideMenuViewController?.hideMenuViewController()
break
default:
break
}
Can anyone please help?
break
lines (except thebreak
afterdefault
), abreak
at the end of a case is not needed in Swift. Second of all, you're explicitly telling the table view to deselect the cell in the linetableView.deselectRowAtIndexPath...
. Third of all: What isappDelegate
for? It's not used in the code.cell
isn't used either. You must not create reused cells outsidecellForRowAtIndexPath
anyway.