【问题标题】:Highlight active link in SWRevealViewController突出显示 SWRevealViewController 中的活动链接
【发布时间】:2014-07-05 01:40:27
【问题描述】:

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

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

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

任何帮助将不胜感激。

干杯

【问题讨论】:

    标签: ios objective-c xcode xcode5 swrevealviewcontroller


    【解决方案1】:

    我不确定这实际上是与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

    【讨论】:

      【解决方案2】:

      我最终使用 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];
      }
      

      【讨论】:

      • 如果用户从滑出菜单中选择相同的视图,我不想重新加载视图
      猜你喜欢
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-19
      • 2016-11-27
      • 1970-01-01
      相关资源
      最近更新 更多