I'm using SWRevealViewController in my project to create a slide out menu for my app.
Is it possible to highlight the currently active link in the menu which the slide out holds?
I've tried sending a page reference identifier to the sidebarviewcontroller but it seems like this has no effect as the view is only loaded once when the app launches and is then simply shown and hidden.
Any help would be much appreciated.
Cheers
I'm not sure that this is actually a question related to SWRevealViewController
. Most likely your rear/bottom/menu view is really a UITableViewController
. If that is that case then the solution is simple. Request that the UITableViewController
remember its selected state.
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
}
This solution comes from: UITableView doesn't keep row selected upon return
I ended up doing this using NSNotification center. In each view controller's viewWillAppear I added...
// Send notification containing page reference to be picked up by sidebar view controller
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"homePage" forKey:@"page"];
[[NSNotificationCenter defaultCenter] postNotificationName: @"activePage" object:nil userInfo:userInfo];
Which was picked up in the SidebarViewController viewDidLoad...
// Pick up the page reference notification and trigger receivePageReference function
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivePageReference:)
name:@"activePage"
object:nil];
Then in the receivePageReference action...
-(void)receivePageReference:(NSNotification *)notification{
I reset all labels to a non-bold font
// Reset all labels to non-bold font
UILabel *homeLabel = (UILabel *)[self.view viewWithTag:12];
homeLabel.font = [UIFont fontWithName:@"Colaborate-Thin" size:19];
UILabel *liveLabel = (UILabel *)[self.view viewWithTag:13];
liveLabel.font = [UIFont fontWithName:@"Colaborate-Thin" size:19];
UILabel *racesLabel = (UILabel *)[self.view viewWithTag:14];
racesLabel.font = [UIFont fontWithName:@"Colaborate-Thin" size:19];
etc..
and set the label with the corresponding page reference to bold...
NSDictionary *notificationInfo = notification.userInfo;
if ([[notificationInfo objectForKey:@"page"] isEqualToString:@"homePage"]){
UILabel *homeLabel = (UILabel *)[self.view viewWithTag:12];
homeLabel.font = [UIFont fontWithName:@"Colaborate-Medium" size:19];
}