突出显示SWRevealViewController中的活动链接

时间:2014-05-16 14:38:12

标签: ios objective-c xcode xcode5 swrevealviewcontroller

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

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

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

非常感谢任何帮助。

干杯

2 个答案:

答案 0 :(得分: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 upon return

答案 1 :(得分: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];

等。

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

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];
}