in my application create sliding menu using SWRevealViewController
when i click on uiviewcontroller sliding menu not close automatically if view controller contain tableview on other click event
how can i solved this problem
my code is :
SWRevealViewController *revealController = [self revealViewController];
[self.view addGestureRecognizer:revealController.panGestureRecognizer];
Write this code on your green view viewdidload method to navigate to another view.
revealController=[[SWRevealViewController alloc]init];
revealController = [self revealViewController];
[self.view addGestureRecognizer:revealController.panGestureRecognizer];
revealController.delegate=self;
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
I solve it using this :-
SWRevealViewController *revealController = [self revealViewController];
[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];
[self.menueBtn addTarget:revealController action:#selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
selector (revealToggle:)call SWRevealViewController class
Related
I am trying to use the SWRevealViewController without a storyboard and with a UIButton. My project has two UIViewControllers with nib's. The main one is called ViewController and the other is called MenuViewController.
In my ViewController I have the following code:
- (void)viewDidLoad {
[super viewDidLoad];
MenuViewController *menuView;
SWRevealViewController *revealViewController = [[SWRevealViewController alloc] initWithRearViewController:menuView frontViewController:self];
if ( revealViewController )
{
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
- (IBAction)toggleMenu:(id)sender {
NSLog(#"Toggling menu");
SWRevealViewController *revealController = self.revealViewController;
[revealController rightRevealToggleAnimated:YES];
}
The toggle menu button prints "Toggling Menu" as expected but doesn't reveal the menu controller. I know this isn't the conventional way of using the SWRevealViewController but does someone have any ideas how to get this to work ?
Add below line in viewDidLoad()
self.revealViewController.delegate = self;
Here are two methods I use to set up the two (left and right) view controllers for SWRevealViewController. Just call them in viewDidLoad.
-(void) initSlideMenu
{
SWRevealViewController * menuViewController = (SWRevealViewController *)self.revealViewController;
if (menuViewController)
{
[_menuButton setTarget:self.revealViewController];
[_menuButton setAction:#selector(revealToggle:)];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
-(void) initRightMenu
{
SWRevealViewController * rightViewController = (SWRevealViewController *)self.revealViewController;
if (rightViewController)
{
rightViewController.rightViewRevealOverdraw =0.0f;
[_notificationButton setTarget:self.revealViewController];
[_notificationButton setAction:#selector(rightRevealToggle:)];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
}
You can try this one with some modifications. It helped in my case.
- (IBAction)toggleMenu:(id)sender{
[self.btn addTarget:self.revealViewController action:#selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
}
I have an example of SWRevealViewController from github.
And now I'm tryng to understand, how switch my independent UIViewController to another, which is including in SWRevealViewController.
I read somewhere that this should work:
- (IBAction)action:(UIButton *)sender {
SWRevealViewController *swcontroller = self.revealViewController;
if (swcontroller) {
self.revealViewController.frontViewController = [[UIViewController alloc] init];
}
}
and I create a modal segue from my UIButton to SWRevealViewController.
But it does not work.
Can anybody give an example?
As per my information you need to manually push or pop your view controller in SWRevealViewController.As shown below try this..
- (IBAction)btnActionSalesQuotation:(id)sender{
SWRevealViewController *revealview = self.revealViewController;
SalesQuotationsViewController *Gosalequo=[[SalesQuotationsViewController alloc]initWithNibName:#"SalesQuotationsViewController" bundle:nil];
[revealview pushFrontViewController:Gosalequo animated:YES];
}
That code helped me:
- (IBAction)act:(UIButton *)sender {
SWRevealViewController *sw = [self.storyboard instantiateViewControllerWithIdentifier:#"SWRevealViewController"];
UINavigationController *nav = [self.storyboard instantiateViewControllerWithIdentifier:#"NavigationController"];
[sw setRearViewController:nav];
sw.frontViewController = nav;
[self presentViewController:sw animated:NO completion:nil];
}
I forgot to add setRearViewController
In my xcode project, I want a UIButton to open a right slide-out menu using SWRevealViewController but it isn't working. Any help?
He's the code in my view didLoad for the UIButton:
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[sidebarButton addTarget:revealViewController action:#selector(rightRevealToggle:) forControlEvents:UIControlEventTouchUpInside];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
And here is the IBAction for the button:
- (IBAction)reveal:(id)sender {
SWRevealViewController *revealViewController = self.revealViewController;
[self revealViewController];
}
I am using storyboard in xcode.
Ok, so I fixed the issue. In my storyboard file instead of "sw_rear" segue identifier I put "sw_right" and that was it.
I'm trying to transition our app to use SWRevealViewController to give us a side-bar on each side of the application. But despite following the code in one of the example apps, I'm getting an error where the ViewController for the front view doesn't work properly. viewDidLoad gets called, but everything remains black.
Interestingly, if in my viewDidLoad, I set the background colour to red of the view, this is reflected. But stuff in Interface builder from the original story board is not.
The code I use in the AppDelegate is:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
MainViewController *frontViewController = [[MainViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
RightViewController *rightViewController = rightViewController = [[RightViewController alloc] init];
rightViewController.view.backgroundColor = [UIColor greenColor];
revealController.rightViewController = rightViewController;
//revealController.bounceBackOnOverdraw=NO;
//revealController.stableDragOnOverdraw=YES;
self.viewController = revealController;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - SWRevealViewDelegate
- (id <UIViewControllerAnimatedTransitioning>)revealController:(SWRevealViewController *)revealController animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
if ( operation != SWRevealControllerOperationReplaceRightController )
return nil;
if ( [toVC isKindOfClass:[RightViewController class]] )
{
if ( [(RightViewController*)toVC wantsCustomAnimation] )
{
id<UIViewControllerAnimatedTransitioning> animationController = [[CustomAnimationController alloc] init];
return animationController;
}
}
return nil;
}
This is the Main.Storyboard which is just for the MainViewController:
When the app loads, the view is just black. But I can drag from both the left and right edge and view the side bars as would be expected. So it's only the FrontView that is coming up black. I stuck an NSLog() into the ViewDidLoad, which appears in the console, as does one in -(void)loadView{}, which shows the View is loading.
If I put into the viewDidLoad a [self.view setBackgroundColor:[UIColor redColor]] this takes effect, meaning it is linked to the view, but it's just the view inside the storyboard is not appearing. Which is weird since the Storyboard also contains a NavigationController, which does appear (I think - unless that navigation controller is coming from somewhere else - which I'm pretty sure it isn't).
Any thoughts on what might be causing this?
I had the same thing going on. I fixed it while looking on the Example code.
In your Storyboard add a UIViewController
Select it and in Identity Inspector just use 'SWRevealViewController' as class
Add a UITableViewController to your story board
Now select your previously added ViewControler and right-click-draw a line to your TableViewController
Select 'reveal view controller set controller'
Click on the newly added Segue and in Attribute Inspector change the identifier to 'sw_rear'
Add any custom ViewController (for example 'MyViewController') to the story board
Select it, then go to the Menu->Editor->Embed In->Navigation Controller
Now a new Navigation Controller should appear
Again right-click-draw a line from the first ViewController to your new NavigationController
Again choose 'reveal view controller set controller'
Now set the identifier of this new Segue to 'sw_front'
Now you have a Basic Setup and when running your app, you should see your custom ViewController. Now the Button for the Menu has to be added.
In your ViewControllers .m add following:
#interface MyViewController ()
#property (nonatomic) IBOutlet UIBarButtonItem* revealButtonItem;
#end
- (void)viewDidLoad {
[super viewDidLoad];
[self customSetup];
}
- (void)customSetup
{
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: #selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
}
}
Now again switch to the story board. Add a UIBarButtonItem to MyViewController. Again right-click-draw a line from MyViewController to this new item in the NavigationBar. Choose 'revealButtonItem'.
Thats it! Repeat the last steps for every ViewController you want to add. You only have to connect them with right-click-drawing from the TableView to your newly added NavigationController of each of your added ViewControllers. To push the ViewControllers just select 'reveal view controller push controller'.
Hope that helps a bit!
I have two programmatically created buttons you can see in my viewDidLoad method. On the modal window I have a button that calls the cancelSearch method via a delegate. When I place a breakpoint on my cancelSearch method it is hit, so I know my delegate is set up correct, but even though it calls this line [self dismissViewControllerAnimated:YES completion:nil]; it's not actually closing the modal window.
The code below is all from my main controller view.
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(showActionMenu:)];
actionButton.style = UIBarButtonItemStyleBordered;
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:#selector(showSearchMenu:)];
searchButtonItem.style = UIBarButtonItemStyleBordered;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:actionButton, searchButtonItem, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.title = #"Census Management";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[[RKClient sharedClient] get:#"censusmanagement" delegate:self];
}
- (IBAction)showActionMenu:(id)sender
{
[self performSegueWithIdentifier: #"CMActionSegue" sender: self];
}
- (IBAction)showSearchMenu:(id)sender
{
ehrxCMSearchView *search = [[self storyboard] instantiateViewControllerWithIdentifier:#"cmSearch"];
search.selectedOptions = self.selectedOptions;
search.delegate = self;
[self.navigationController pushViewController:search animated:YES];
}
- (void)cancelSearch:(ehrxCMSearchView *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
You would dismiss a modal view using something similar to:
[self dismissModalViewControllerAnimated:YES];
This will dismiss the modal view which was loaded using something similar to:
[self presentModalViewController:search animated:YES];
However looking at your code snippet, it appears the search view controller is being pushed onto the navigation stack using the following line:
[self.navigationController pushViewController:search animated:YES];
So I you probably need to pop the view from the navigation stack rather than trying to dismiss it as a modal view:
[self.navigationController popViewControllerAnimated:YES];
If your view controller is modally presented, you should use this:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
The presentingViewController property is available in iOS 5 only. So, if you're targeting older versions of iOS, you have to use self.parentViewController instead (use the appropriate one for each iOS version, you have to handle this).
If you make this control in your parent/presenting view controller, then just call this:
[self dismissModalViewControllerAnimated:YES];