2

我在我的项目中使用 SWRevealViewController 为我的应用程序创建一个滑出菜单。

是否可以在滑出的菜单中突出显示当前活动的链接?

我尝试向 sidebarviewcontroller 发送页面引用标识符,但这似乎没有效果,因为视图仅在应用程序启动时加载一次,然后简单地显示和隐藏。

任何帮助将非常感激。

干杯

4

2 回答 2

6

我不确定这实际上是一个与SWRevealViewController. 很可能您的后/底部/菜单视图确实是UITableViewController. 如果是这种情况,那么解决方案很简单。请求UITableViewController记住它的选中状态。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    self.clearsSelectionOnViewWillAppear = NO;
}

此解决方案来自:UITableView doesn't keep row selected during return

于 2014-07-31T15:15:16.963 回答
3

我最终使用 NSNotification 中心执行此操作。在每个视图控制器的 viewWillAppear 中,我添加了...

// 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 中提取的...

// Pick up the page reference notification and trigger receivePageReference function
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(receivePageReference:)
                                             name:@"activePage"
                                           object:nil];

然后在 receivePageReference 动作中......

-(void)receivePageReference:(NSNotification *)notification{

我将所有标签重置为非粗体字体

// 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..

并将具有相应页面引用的标签设置为粗体...

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];
}
于 2014-05-21T16:25:48.610 回答