SWrevealViewController without using navigationController
where you need to push or model new view controller call the below code
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"yourstoryboardname" bundle: nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"yourIDName"];
[[self navigationController] pushViewController:viewController animated:NO];
SWRevealViewController with NavigationController - Swift 3
Suppose outlet of menu is btn_Menu. In controller's view did load I set bar button's action and target programmatically.
btn_Menu.target = self.revealViewController()
btn_Menu.action = #selector(SWRevealViewController.revealToggle(_:))
Have a look at this image structure that you need. Sorry not very clear but perhaps solve your issue:
SWRevealViewController push to actual navigation controller
Here's your solution
From Menu to Normal ViewController by using Swrevealviewcontroller "setFrontViewPosition"
In Swift
let obj = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
let navController = UINavigationController(rootViewController: obj)
navController.setViewControllers([obj], animated:true)
self.revealViewController().setFrontViewController(navController, animated: true)
self.revealViewController().setFrontViewPosition(FrontViewPosition.Left, animated: true)
In Objectctive-c
-(void)main{
LoginViewController *tar = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tar];
[navController setViewControllers: @[tar] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
swrevealviewcontroller navigation item and bar button missing
navigation controller's
navigation bar will only show up for view controllers that are contained by that navigation controller
. Here, you're presenting
a modal view. It's not contained by the navigation controller
.
If you want the navigation bar to continue to appear:
- If it's purely a matter of style, put a navigation bar on the modal scene you're presenting in the interface builder.
- If you need to modally present a view that should be contained in a navigation controller, then you need to present a navigation controller--not a view controller.
- Finally, if the view you're presenting is intended to be part of the navigation controller's navigation stack, then you need to present it with a push, not a modal segue.
Update
Do like simple ,
and call the perform segue as
[self performSegueWithIdentifier:@"main" sender:self];
Swift SWRevealController without storyboard
You can do it as follow.
Create one function createSlidingMenu
in appDelegate.
func createSlidingMenu(){
let frontViewController = //create instance of frontVC
let rearViewController = //create instance of rearVC(menuVC)
//create instance of swRevealVC based on front and rear VC
let swRevealVC = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController);
swRevealVC.toggleAnimationType = SWRevealToggleAnimationType.EaseOut;
swRevealVC.toggleAnimationDuration = 0.30;
//set swRevealVC as rootVC of windows
self.window?.rootViewController = swRevealVC!;
}
call createSlidingMenu
in application:didFinishLaunchingWithOptions:
and you are good to go.
SWRevealViewController toggle not working with custom Navigation Bar Button
class Name: SWRevealViewControllerDelegate
override func viewDidLoad() {
super.viewDidLoad()
self.revealViewController().delegate = self
}
SWRevealViewController - RightViewController
I figured out what the problem was. In loadStoryboardControllers
method [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
was commented out. If we implement right view controller this has to be uncommented.
How to show side menu with swrevealviewController when revealview controller does not exist?
i weel i at last resolved how to show the side menu comming from the appdelagte when push notification is recived.
so the idea is to instancita a navigation controller before the viewcontroller to present to have navigation bar.
let menuVC = storyboard.instantiateViewController(withIdentifier: "menuVC")
let chatVC = storyboard.instantiateViewController(withIdentifier: "chatNC")
((chatVC as! UINavigationController).topViewController as! newChatViewController).id = id
let mainRWVC = storyboard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
mainRWVC.setRear(menuVC, animated: true)
mainRWVC.setFront(chatVC, animated: true)
self.window?.rootViewController = mainRWVC
self.window?.makeKeyAndVisible()
then in the topViewcontroller of the presented navigation. check for id is not nil then present the next view. and then in the presented view. in the did load this code show show the side menu.
self.navigationItem.leftBarButtonItem = nil
let revealViewController = self.revealViewController()
revealViewController?.rearViewRevealWidth = ((UIScreen.main.bounds.width * 74.6875) / 100)
if revealViewController != nil{
let button1 = UIBarButtonItem(image: UIImage(named: "ico_menu"), style: .plain, target: self.revealViewController(), action: #selector(SWRevealViewController.revealToggle(_:))) // action:#selector(Class.MethodName) for swift 3
self.navigationItem.leftBarButtonItem = button1
self.navigationItem.leftBarButtonItem?.tintColor = .white
}
and voila the side menu appears and works as expected.
Related Topics
Change Uitableview Height Dynamically
How to Turn Page Programmatically in Uipageviewcontroller
How to Wrap Text in a Uitableviewcell Without a Custom Cell
Trying to Handle "Back" Navigation Button Action in Ios
Using Ssl in an Iphone App - Export Compliance
Swift - Stored Values Order Is Completely Changed in Dictionary
Ios9 Getting Error "An Ssl Error Has Occurred and a Secure Connection to the Server Cannot Be Made"
How to Get a Plist as a Dictionary in Swift
How to Debug iOS 8 Extensions With Nslog
Uiviewcontroller Returns Invalid Frame
iPhone Sdk: Differencebetween Loadview and Viewdidload
Error Opening iOS Simulator with iOS 8 Beta Version: "Unable to Boot the iOS Simulator"
How to Save Local Data in a Swift App
How to Make Drawrect Work Right Now