我使用SWRevealViewController
到在我的應用程序中添加了側欄菜單。我有我的SideBarViewController
我設置視圖控制器,可以說OptionAViewController
。我使用顯示視圖控制器segue來打開這個新視圖OptionAViewController
。從OptionAViewController
我想實現一個返回按鈕返回到SideBarViewController
。SWRevealViewController中的後退按鈕
這是我如何設置optionAViewController
。這工作。
//SideBarViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue isKindOfClass: [SWRevealViewControllerSegue class]]) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
//[navController pushViewController:dvc animated: NO ];
[navController setViewControllers: @[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
而且這是我想實現在OptionAViewController
後退按鈕。我嘗試了popViewController
但它崩潰。我也嘗試了其他選擇,但是他們都沒有工作。你知道選擇者應該是什麼?
//back button in ViewDidLoad (OptionAViewController)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"backButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(popViewControllerAnimated:)forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barButtonItem;
這將回到側面菜單,但以當前視圖(OptionAViewController)作爲後視圖。我想實現一個返回按鈕返回到:SideBarViewController在前面和MainViewController在後面,當我第一次按下我的側邊欄圖標時它也會出現。 – nabrugir