views:

36

answers:

1

I followed Luke Redpath's suggestion here - http://stackoverflow.com/questions/2803061/selected-uitableviewcell-staying-blue-when-selected - to deselect the row when returning to the original table view, but I can't get it working. In fact the method doesn't get triggered.

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

I suspect this is because the class isn't a UITableViewController, but a UIViewController with the tableView as a property connected up to the NIB.

How would I get the same behavior - ie deselecting when returning?

+1  A: 

If you are using a NavigationController, you can do it with its delegate:

- (void)navigationController: (UINavigationController *)navigationController
       didShowViewController: (UIViewController *)viewController
                    animated: (BOOL)animated
{
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

But you have to check whether the show controller is which you want =/

[EDIT] Create the outlet and link it in IB to NavigationController

@interface MyInt <UINavigationControllerDelegate>
{
    IBOutlet UINavigationController *navigation;
    ...
}
@property (nonatomic, retain) UINavigationController *navigation;
...
@end

@implementation MyInt
@syntesize navigation;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigation setDelegate: self];
}
...

@end
grilix
My nav controller is created in my nib, so it has no corresponding class. Is there way around this?
cannyboy
You can map it to an IBOutlet ivar.
Peter DeWeese
My setup is that I've got a MainViewController class with a corresponding NIB. That nib has UITabBarController (also an IBOutlet property 'tabBarController' in MainViewController). Within that tab bar are several UINavigation controllers. These are not referenced in code. So I am not sure how to access any of these nav controllers
cannyboy
How do you push controllers onto navigation controller ?
grilix