aryaxt / iOS-Slide-Menu

iOS Slide Menu with ability to add both left and right menu, and built in gesture recognizer. Similar to Path and Facebook
Other
1.53k stars 359 forks source link

Bar buttons now update when changed #155

Open gdisco opened 9 years ago

gdisco commented 9 years ago

Love this subclass :). Had an issue while implementing it though: I created my SlideNavigationController using - initWithRootViewController (I don't use storyboards), and then I added a custom leftBarButtonItem, but the custom button wasn't showing up. I discovered that this is because the bar button items only update when a view controller is pushed onto the navigation stack. Since I was adding the custom button AFTER I added my root view controller, it wasn't getting updated. This patch overrides the setters on the bar button items such that they get updated whenever they're changed.

aryaxt commented 9 years ago

Sorry been a while. Will look into this after I fix the landscape bug

coolcool1994 commented 7 years ago

Yeah I can confirm this bug. If I add leftBarButtonItem in Storyboard and set an action outlet and do [[SlideNavigationController sharedInstance] toggleLeftMenu];, the leftBarButtonItem wouldn't show up. Also if I add it in AppDelegate using code:

UIButton button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; [button setImage:[UIImage imageNamed:@"menu@3x.png"] forState:UIControlStateNormal]; [button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleLeftMenu) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; [SlideNavigationController sharedInstance].leftBarButtonItem = leftBarButtonItem;

This leftBarButton item also disappears. Only if you call above methods in viewdidload of a particular tabbar, the leftBarButtonItem would show up. This seems definitely like a bug.

gdisco commented 7 years ago

Hey @aryaxt looks like this bug is still outstanding after all this time, and at least one other person would benefit from the fix! What do you say about merging in the pull request? Should be basically a no-op for you, github has verified there's no conflicts.