我在我的应用中使用SASlideMenu组件,并使用自定义segue将新的UIBarButtonItem添加到目标视图控制器。它与默认用例略有不同,因为我在应用程序中间使用组件而不是从它开始。代码是:
SASlideMenuViewController* source = self.sourceViewController;
SASlideMenuRootViewController* rootController = source.rootController;
UIViewController* destination = self.destinationViewController;
UIButton* menuButton = [[UIButton alloc] init];
[rootController.leftMenu.slideMenuDataSource configureMenuButton:menuButton];
[menuButton addTarget:rootController action:@selector(doSlideToSide) forControlEvents:UIControlEventTouchUpInside];
UINavigationItem* navigationItem = destination.navigationItem;
navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
但视图控制器中的UINavigationBar没有添加任何按钮。
来自SASlideMenu(https://github.com/stefanoa/SASlideMenu)的演示应用程序在UIViewController之前将segue转到UINavigationController,原始代码为:
SASlideMenuViewController* source = self.sourceViewController;
SASlideMenuRootViewController* rootController = source.rootController;
UINavigationController* destination = self.destinationViewController;
UIButton* menuButton = [[UIButton alloc] init];
[rootController.leftMenu.slideMenuDataSource configureMenuButton:menuButton];
[menuButton addTarget:rootController action:@selector(doSlideToSide) forControlEvents:UIControlEventTouchUpInside];
UINavigationItem* navigationItem = destination.navigationBar.topItem;
navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton];
在我的应用程序中,通过来自另一个UIViewController的push segue访问根视图控制器,因此segue将直接进入UIViewController。谁能明白为什么这不起作用?