iOS - UIPopOverController - Dynamic Menu? - ios

I know UIPopOverController can give a standard drop down but I'm curious if it can do a dynamic drop down.
The Dynamic drop down would take it one step further and clicking on any item in the list could expand out more options or preform some other action, similar to how file menus behave.
If any examples exist that would be appreciated.

There's no compelling reason why not, but you'd just have to write it all yourself (in a table view or otherwise). Popover controllers are just containers for view controllers: write a view controller that does what you want, and you're set.

Related

How many view controllers would I use in this app setup?

I am very new to iOS programming and iOS code design, and I am working on developing a simple iPhone application. The basic layout of my application is as follows:
In the first page, the user is presented with a list of categories. Upon clicking on a category, several options with drop down. Upon clicking on an option, the application will transition to a page where the user will input a number of values and be presented with an output. How many view controllers would I need for this application? Based on the little experience I have, I was thinking of using a view controller for the main page and then one for each option, but is this necessary? Is there a way I could use less view controllers?
Depending on how complicated and different each option is, you may be able to use one view controller for all options.
So..
Main view controller- Shows a list of categories, where options could show underneath when tapped
Option view controller- Shows input boxes with labels and an output box. You may show/hide different inputs based on how many you need and you can change the label text accordingly.
This would give your app the smallest UI with the most flexibility, in case you added more options.
Of course design is very subjective and depends on the deeper details of the project, but based on your description, I would implement it with 2 view controllers.
If the screen where you input the values can be generalised, then you will have only 2 view controllers.
But in the implementation of the first one, you will have to implement function:
func prepare(for: UIStoryboardSegue, sender: Any?)
to pass the data about the selected item. And the the second view controller should adjust its fields accordingly.

Swift iOS solution for multiple/relational drop down pickers

I am new to programming iOS and I am not sure on how to implement multiple/relational drop down pickers into my design.
I have a search form in my app that works like a panel-menu. If you click on the search icon then the panel slides in with the search form.
But what is the best way to implement multiple/relational drop down pickers for my search form?
The pickers are relational. First you select a state then you must select a city. Once you selected a state in dropdown1 then dropdown2 should get populated depending on what you selected in dropdown1.
So is there any good solution for this when it comes to design?
I would like to show both pickers at all time. Kinda like a datepicker when year / month / day always is shown.
But if anyone has a good resource example on relational pickers please share.
Thanks in advance,
You can set this up with nested UITableViewControllers.
These types of projects are generally called Master/Detail.
The Master tableView would display the list of categories.
Once the user has selected a category, the specific category is passed to the detail View controller. It queries all the subcategories for that category.
This can all by done in Storyboard, using Auto Layout, self-sizing cells, and a combination of show and unwind segues.
A show segue pushes a (table) view controller onto the navigation controller stack. In your case, the category controller would push a subcategory controller. prepareForSegue:sender: is where the category controller would provide the category to the subcategory controller.
An unwind segue returns from a view controller, popping it off the navigation stack. In your case, the subcategory controller would return (with the selected subcategory information) to the category controller, or a previous view controller.
It may sound like a lot to digest, but if you read up on recent (i.e. for iOS 8) walkthroughs which use these concepts, you'll have learned some acceptable practices for how information and control should flow within an app.
There's one more thing I didn't mention, called Core Data. Core Data, and NSFetchedResultsController would be a great tool to learn and use for the app. It's probably more complex than anything I previously mentioned, but once you get a handle on it, you will really appreciate it, and may end up using it in many apps!
Don't get too bogged down with how your app should look. Focus on how the model and view controllers are written, and get a good understanding of the underlying frameworks. That's more important right now, than any fancy transition/animation.
The design of any app will evolve as you use it. You'll discover what works well, and what doesn't, so don't get too attached to any one way of organizing the data!
Hope that helps! Enjoy programming for iOS, it's a great platform!

Storyboards: How do I use the same view controller in several places?

For years, I've hand-coded my view code for iPhone apps, but now I'm giving storyboards another look.
One common pattern in my code is to use the same view controller in two places, but with slight UI variations. For example, when browsing a list of brands (BrandListController), I'd like to show a table view of all brands in the system; tapping a brand shows you its products. But when filtering items by brand, I'd like to show a table view of brands (with the same content and same cell appearance), but I'd like tapping a row to take you back to the filter screen instead of showing you that brand's items. I'd also like a "Search" bar button item in the top right.
It's easy to make these things happen in code, by just adding a boolean member variable so the controller can be configured before it's presented.
But how would I do this with storyboards? I could have multiple controllers segue to the same instance of BrandListController, but again, I would want the controller to have different behavior and include/exclude UI elements based on how it's used. It seems like a bad idea to create two separate instances of BrandListController in the storyboard, because then I would have to duplicate all the outlet connections and I would have to keep changes in sync. But what are my other options?
The thing to realise with Storyboards is that you don't necessarily have to only use a single storyboard.
You can use multiple storyboards or use them in conjunction with nibs etc...
However, in this case what you could do is still use you boolean property on the controller.
Then in the prepareForSegue method of the other controllers you can set this boolean property to change the behaviour. You might even have a couple of nibs that defines a small section of UI to place into the view depending on the property.
I've done stuff like this to pass blocks into view controller too.
For example...
I had a "User Search" controller that had a default behaviour of if you tap a user it will push to that user's profile page.
But I could pass in a code block that would, for instance, dismiss the search controller and I use the selected user to create a new message to them (or whatever). Or something else entirely depending on the code block I passed in.
EDIT
LOL, just re-read your question. What I did with the blocks would work for you too. I created a block property called userTappedBlock or something. If that exists then I run it when the cell is tapped. If not I do the default behaviour.

Is there a different implementation to avoid my long switch statement?

In my iOS app, I have a view containing around 33 buttons (I'm creating an interactive map). Each button corresponds to a building. And each button I want to modally present a different view controller based on the selected button.
So my first thought was to tag all the buttons, and create a 33 case long switch statement. Looking at my code, there has to be a better way to do it, but my brain isn't coming up with the solution. Any advice?
Use the button tag as the index into an array giving you the configuration for the view to show.
If you are using different view controller classes for the presentation of some buildings then you can have an identifier (or, if you want, the class name) in the configuration.

iOS - Use Tabs as a Filter

Is it possible to use tabs to act as a filter for a list view?
I know you can add new tabs by hooking them up to new view controllers, but I would ideally like to use the same view controller, but show different items based on which tab is selected.
Can anyone point me into the right direction?
I think you may want to use a UISegmentedControl instead. It looks kinda like a tabbar and of course you can use it to filter list results.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html
I would not suggest using tab for that purpose.If the filtered results are to be shown in the same view controller you can use Segmented Control with various segments.
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SegmentedControl/Articles/SegmentedControlCode.html

Resources