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