what can be used instead of new uiviewcontrollers - ios

I am developing an iOS app which have 3 main uiviewcontrollers and more than 50 different forms.
I completed designing main forms (login, form selection and message uiviewcontrollers). User will select any form and related form will be loaded. But I do not want to use tab or tableview controller and create more than 50 viewcontrollers in my application. Because all contents are amost same (including a long text and one button).
I would like to create something like subviews (I use usercontrol (ascx) in .net web apps) or or anything else. but do not want to create many viewcontrollers.
What can I use for my forms? Then I will load the content by user selection.
Can you help me?
Thanks for any help.

You could 'group' the forms and see which elements stick together a lot.
Make those subviews of UIView in code and re-use them by adding them programmatically to populate your VC.

From my understanding of your application, you should present your forms as ModalViewControllers. This way you will present the forms when needed and dismiss them once "Submit" is hit for example. Then the form can pass information to its delegate (which can be the main view controller) through a delegate method.
Here's a good tutorial on using ModalViewControllers: "Presenting View Controllers"

Related

Swift iOS Application Best Approach - Book With Input

I am attempting to build an application in swift that is essentially a book and some pages of this book allow for user input that is stored in the application.
I am new to swift and am unsure of the best way to approach this problem. So far I have tried using a Page View Controller and separate View Controllers corresponding to each page. The Page View Controller class navigates through the pages using Storyboard IDs to instantiate the View Controllers in an array. This works in creating a navigable book but I run into issues when trying to create outlets from the text fields on some pages since essentially the View Controller is instantiated each time its accessed and so it does not permanently exist.
I am totally and utterly lost as to where I should go from here. Any advice/wisdom will be deeply appreciated.
Thank you
simplest Approach is Collection-view with pagingnation(self.collectionView.pagingEnabled = YES).
https://medium.com/#shaibalassiano/tutorial-horizontal-uicollectionview-with-paging-9421b479ee94
create multiple cell one for your Page(reading) and second for input field.
it also helps for memory management. because cell are reusable. and cell that are visible to Screen are only loaded in memory.
you can also Create Custom layout for animation as per your requirement.

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.

Implementing PageViewController in Swift

I can't seem to get a simple answer to this anywhere. I have a Page View Controller and similar lay-outs for all of the other view-controllers.
This is working without problems if I have one view-controller per view, but it seems very inefficient given that all the lay-outs are the same.
I've seen tutorials like this, but not for Swift. Is it possible to use a single view controller for all the pages and just switch out the text or images? If so, can you please explain how this is done?
All you have to do is make each page link to the same viewController and then dynamically change the content on each page based on the page number associated with it. You could easily have some elements that were hidden or diabled on certain views.

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.

How to create user control [common control] in iOS Xamarin

I want to create a common view / control which will be used in many view controller pages. For e.g. header control which has logo, logout and home button which will be used in many other view controller pages in Xmarin iOS.
Is there any way to create 1 common control / view which I can use any all the pages so if any updates in future, I can change it from 1 page only without updating in all the pages.
Do you mean Custom Controls for iOS? If yes, Xamarin has a couple of articles for that in their guides: explanation and walkthrough. The designer even supports the custom controls which are a subclass of UIView or UIViewController. I guess all information you need should be there.

Resources