XCode - How to change button destiny with segmented control - swift

I'm building an app right now and I have a problem with the combination of button and segmented control, if it's even possible.
Right now I have a segemented control, where you can chose between 7 different values. On the same page, I have a button leading to the next page. Now I want my button to lead to a different page, depending on the selected value in the segemented control.
My segemented control is located in my ViewController.swift and my button in Main.storyboard.
I looked in the code of it and found the destination of the first page the button has to lead to, but I can't figure out how to make it dependent on the segemented control. Simple "if" commands seems not to work in ".storyboard",
Could someone help me out?

not sure that you can do this from just the storyboard, I would have the button reference an IBAction in the view controller. The action could use a switch statement (or a series of if/else statements) to call different segues based on the state of the segmented control.

Related

Storyboards multiple buttons cause same segue

I'm working on trying to figure out storyboards and it all seems pretty cool but I'm having problems with moving from one screen with a few buttons to another screen no matter which button is pressed. Obviously I can control drag from each button but then I have segues all over the place on the story board and I feel like there has to be a better way to do it. I've tried highlighting all the buttons and control-dragging to the next screen but that only caused the one I dragged from to work.
Here's an illustration of what I have that works right now...
If I have to stick with this then so be it but I'm going to end up with 6 buttons on one page and 8 on another. That's alot of segues. Basically each button signifies a choice for the user. That choice will cause different things to happen behind the scenes but no matter which button they choose they move to the next screen.
What I've Tried:
Highlighting all the buttons and then dragging to the next view controller.
This failed because it only connected the segue to the button I clicked on when I control-dragged
Dragging out one segue then dragging from the second button to the circle part of the segue.
This caused nothing at all to happen.
I'm unaware of a way to give a single segue multiple triggers in a storyboard, however you could create a single segue with a particular identifier, and then have all of the buttons respond to a single IBAction that calls [self performSegueWithIdentifier:...];
Check out generic segues, which are tied to the source view controller instead of an IBAction:
https://stackoverflow.com/a/8868096/295130

How can I toggle a UITabBarController's button destination between two ViewControllers

I'm a bit stumped with this one...
Consider this app:
The app has a tab bar navigation at the bottom with buttons recipes, favourites and settings
Recipes can be shown in two ways - either as a list, or as an grid of images.
The user can toggle between the list and grid views by pressing the toggle button and the app should remember the previous setting.
So...
I boot the app and press the Recipes button.
I'm looking at the recipes as a list and I press toggle
The screen flips (via UIModalTransitionStyleFlipHorizontal) and now I can see the recipes arranged as a grid.
I press settings to change some settings.
When I press Recipes again the recipes should still be listed as a grid.
When I press the toggle button, the recipes are shown as a list again etc.
The Problem...
Assuming the list view is the default, how do I tell the newly instantiated grid view that it should use the same TabBar as the list view?
How can I make this transition look seamless?
I understand that I shouldn't use one controller for multiple views, or one view across multiple controllers... Should I use a separate view/controller for each screen here or use the same and show/hide subviews as required?
All advice appreciated
You need two separate ViewControllers for both screens.
If you want to make it as you show, take Xcode template called "Utility application" as a base.
I believe better to use here UITabBarController.
I recommend you also to read Human Interface Guidelines from Apple.

Add Up/Down buttons to UITableView navigation bar

Many apps, including Apple's own native Mail.app on the iPhone implement an Up/Down button in the detail view which allows for quick and easy browsing. I wish to create such an interface in my own app, but am struggling to do so. So far I've setup a segmented control which links to an action in my navigation bar, but I'm struggling with what to put in the action to make the detail view for the table update when the user presses the "Up" button or "Down" button to navigate to the item before or after the current one.
Any help would be appreciated. Thanks.
It depends on how you have your data set up, but why can't you hook into your existing code? What are you doing in your existing code to refresh the detail view when a user selects a row in master view table? Can't you just call that method directly?
It's hard to give specific advice without more detailed information on your current design.

iphone persistent button on all views

I have a navigation app that has many screens the user navigates to. A handful of views manages these screens dynamically. What I want to try to do is add a button that will always show up on every screen the user views. I need to do this so that the user is always able to preform the action associated with the button regardless of where they are in the app.
Is it possible to achieve this by adding this button only once and having it passed between views like my navigation bar is? Or do I just have to man up and add this button and its functionality to every single view file I have?
Thanks
I would say it probably depends on what the button does. If the button is generic to all views, meaning it affects all views the same exact way so no customization for a given view is needed, then a way to do this would be to include the function in the App Delegate or as a subclass to your Navigation controller.
You can then use the rightBarButtonItem to always show the same button and just access that method. You would just have to add code for the rightBarButtonItem in each viewDidLoad (but they'd all be the same).
I did something similar to this with an "Upgrade" button on one project. Since all the button does is launch the AppStore to the paid version, it's independent of all views and I can place it anywhere.
You can put the button on the navigation bar if you want. Alternately, the more generic way to do this would be to split your single view into two views. One is small and only contains your button but always stays on the screen. The second is your workspace and you swap in and out the views that are displaying the current content. You'll note that this is the way the navigation controls and tab-bar controls work.
The last way to do this would be to put different buttons, in the same place, on each view and have them all trigger the same action. As far as the user is concerned this looks like the same button. Disadvantage here is that you can't alter the button across all views in a simple manner.

Modifying code to add a home button

Currently the code I need to modify uses a tabBarController with a single selection inside it which takes the user back to the root view, but because it is a tabBar then the whole of the tab is selectable and I need it so only the button positioned in the middle of the tab bar is selected.
I am fairly new to this but know it is not a tabBar that is needed here but something else, maybe just place a button there. Any help would be fantastic. I would post the code up but I am unsure which section would be required. I hope I made myself clear enough :)
Rowley
Tab bars are for switching among different views. If all you want is a home button, a tab bar would not be a good choice. You could use either a simple UIButton, or possibly a tool bar -- though the tool bar is generally used when there is more than one action the user might take.