I am using SWReveal. Everything works fine except that I would like to be able to go back to the view controller from which I fired the sidebar.
For example, let's assume I have 2 view controllers: VC1 and VC2.
I'm on VC1. I open the sidebar and select the option to move to VC2. I then want to move back to VC1 but not via the sidebar (imagine that VC2 is a settings page that is applied to a table on VC1 - I do not want to have a button on a tool bar for the odd occasion I am going to use this functionality so I'd rather it lived in a sidebar menu).
If I was not using a sidebar menu, a simple segue from VC1 to VC2 via a button would enable me to use the 'back' button.
Is there a way to achieve this kind of behaviour with SWReveal sidebar menu?
I faced the same issue on my application first i add a segue to the main menu of type modal with identifier then in the prepare for segue i put that code
if ([[segue identifier] isEqualToString:#"backtologin"]) {
MWViewController *controller = (MWViewController *)segue.destinationViewController;
}
Related
swrevealview controller side bar menu wont dismiss after open another view controller [swift]. How should i close it?
There is menu close event in that controller.
You can manual close menu before you going to push other view controller in UINavigationcontroller.
You can use below code and do some logic with your app navigation functionality.
// Sets the frontViewController using a default set of chained animations consisting on moving the
// presented frontViewController to the right most possition, replacing it, and moving it back to the left position
- (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated;
I have a UIBarButtonItems, left side is edit and right side is add/done;
Now When edit is not clicked the action for right side button is to take me to next view controller and I have setup this using segue in storyboard.
However when edit is clicked I want to perform a different action i.e I don't want to go to that new view controller rather disable editing when clicked on that right side UIBarButtonItem.
Now I also have a IBAction done; which disables the editing.
But how to shift the behavior between add/done;
I can do this via programming; But since I have added the segue via storyboard, I wanted to know if there is a way I can switch between segue from storyboard and the IBAction in my controller.
Thanks.
Your problem is that you connect button action to perform specific segue.
You can
create segue between your controllers by Ctrl+dragging from one VC to another (not from specific view to view controller). You can do it easily in VC list window (to the left of your Storyboard scene). Don't forget give IDs to your segues.
connect your button actions to VC action listeners
in these listeners use your logic and invoke with specific identifier
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
That's all!
I have two View Controllers, I need to have a button in ViewControllerOne that when I press it Show me ViewControllerTwo.
In storyboard I related both views with a "Presenting Segues" - Push modal. And both views have a view controller class.
I'm not sure what you mean by "I related both views with a 'Presenting Segues' - Push modal." Are you using a navigation controller and want a push segue, or do you want to do a modal segue? A "push modal" is a contradiction in terms.
So, let's imagine that you want a modal segue. So, you put a button on the first view, right-click and drag (or control-click and drag) from that button to the second view.
You'll get a pop up asking for type of segue. Select "modal".
And you're done transitioning from 1 to 2. No code necessary.
If you want a button on the second view to take you back to the first view, you do not want a modal segue from the second view back to the first view, but rather you want to dismissViewControllerAnimated. You can do this via a custom segue, or easier, just have a button which calls dismissViewControllerAnimated. Thus, you'd add a button to the second view, and while the editor is in in "assistant" mode (where the associated .h file is showing below the interface builder; see below if you want to know how to show the .h file at the same time as the Interface Builder screen), right-click (or control-click) and drag from the button on the second view down to the second view controller's .h file:
By the way, if you don't see the .h file there, click on the "assistant" editor button and choose "automatic" for the files to be shown down there, and you should be good:
It will then show you a pop up asking you what you want to do. Select IBAction and give your new method a name:
Then go to your code for the view controller, and add the dismissViewControllerAnimated code:
All that code says (and in this example, I just called my IBAction dismissTwo) is:
- (IBAction)dismissTwo:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If you want to do a push segue, it's even easier. First, if you don't already have a navigation controller, add one by selecting the first view and choose "Embed in" - "Navigation Controller":
When you do this, you'll have a new navigation controller (which you don't really need to do much with) and the first view will have a navigation bar.
Now, right-click (or control-click) on your first view's button and drag over to the second view:
This time, select the "push" segue:
And you'll know that it worked, because your second view will have a navigation controller
You don't need a button to go back, because the navigation controller will automatically have a "Back" button, so you don't need to add your own.
This is how you achieve a push segue.
I have this code running when I tap a button:
[self performSegueWithIdentifier:#"services" sender:self];
NSLog(#"ButtonClicked");
I can see the log message appearing each time I press the button but the segue isn't activating.
In my storyboard file I have a segue named services, that's the segue I want to activate.
Any idea where I'm going wrong?
Edit
The button is inside a tab bar controller, will that affect things?
For push you need to embed your source view controller in navigation controller.You can do this as follows:
Select your source view controller, Go to Editor and select Embed In
-> Navigation Controller.
So I have an iPhone application that utilizes a UINavigationController for setting up the views. When the application first starts, it presents the user with a UITableViewController and the user can select an item and it will push another view. Now I have it set so that my app remembers the user's last selection and automatically selects it and loads the correct view controller. The only problem is that I am experiencing a really weird glitch when I load the next view automatically..
When the view is pushed, the navigation toolbar will change so that a back button directed to the previous view is showing but it won't display the next view. It will instead keep showing the table view and I can interact with it as well. I can press the back button and it will change the toolbar back and the tableview is still shown. Then when I select an item it loads the view just fine.
Thanks for the help.
Code:
I determining whether to push the view controller based on whether it can connect to a server. I do this in a backround thread:
- (void)startingThread
{
[NSThread detachNewThreadSelector:#selector(loginThread:) toTarget:self withObject:communicator];
}
- (void)loginThread:(MowerCommunicator *)communicator
{
//If it can connect, launch thread complete.
[self performSelectorOnMainThread:#selector(loginThreadComplete:) withObject:communicator waitUntilDone:NO];
}
- (void)loginThreadComplete:(MowerCommunicator *)communicator
{
//push view controller
}
Now I have added NSLog statements to track if the view is actually "showing" and both viewWillAppear and viewDidAppear get called. I also check the delegate methods for the navigation controller and they get called as well.
I have a view that is the initial startup view and it reads from a server to determine what to display in the next table view. That gets pushed fine and when the tableview gets pushed, I hide the back button so the user can't get back to the first view without closing the app. Then the tableview looks at a variable in NSUserDefaults to determine with there is a saved index and then pushes the next view controller. That is when the glitch occurs. If I then press the back button to "go back" to the table view (this really just changes the navigation toolbar) and then I select an item from the table view, it loads the next view correctly. Also, I call the exact same methods when the user pressed an item from the table view and when the app loads the view automatically.
The simplest explanation is that you're pushing the initial tableviewcontroller onto the navigation controller's stack twice.
If you have the initial tableviewcontroller set as the nav's first controller in a nib but then you push the same controller onto the stack when trying to automatically display the stacked views, you would get what you are describing. The nav starts out with the controller from the nib and then you push another instance on top of that.
You should log the nav's viewControllers property before and after you do the automatic push to see what the actual state of the stack.