问题描述
我在我的项目中使用 SWRevealViewController 为我的应用程序创建一个滑出菜单.
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?
我已经尝试向 sidebarviewcontroller 发送一个页面引用标识符,但这似乎没有效果,因为视图只在应用启动时加载一次,然后简单地显示和隐藏.
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.
任何帮助将不胜感激.
干杯
推荐答案
我最终使用 NSNotification 中心完成了这项工作.在我添加的每个视图控制器的 viewWillAppear 中...
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];
在 SidebarViewController viewDidLoad...
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];
然后在receivePageReference动作中...
Then in the receivePageReference action...
-(void)receivePageReference:(NSNotification *)notification{
-(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];
等等.
并将带有相应页面引用的标签设置为粗体...
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];
}
这篇关于突出显示 SWRevealViewController 中的活动链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!