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.
Related
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.
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!
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"
My UIViewController has a UIPageViewController embedded in it. The pager can contain anywhere from 5-38 pages (each page is an instance of a UIViewController subclass) depending on the situation. I've noticed that depending how complicated I make the UI elements on each page, the app slows down considerably, and is very slow when swiping to go to the next page.
Here's the thing - the view on each page is identical, except for the values of a few UITextViews. I am building the view in each page's viewDidLoad method each time viewControllerAtIndex is called for a new page. I feel like there must be a way to re-use the same view for each page, and just swap the text values that are supposed to be different. Can anyone describe a strategy to do this?
Like I said, every page has an identical view hierarchy except the values for some of the text, so I'm really just looking for a way to maintain one basic view controller per page, but cache the view hierarchy to be re-used on each page, and swap out some simple text values depending on page number.
EDIT
Something I forgot to mention in the original post is that I'm building my view programmatically because the number of elements on the page is dependent on choices the user made on previous screens. i.e. there may be 5 TextViews or 10 TextViews, etc. depending on what the user selected on a previous screen (before coming to the UIPageViewController). With that said, I do not believe an xib based approach will work because the initial layout is dynamic.
Thanks in advance!
Have you tried using a xib based view, which you could pull out of the xib once, and keep a strong reference to it. In your controller's viewDidLoad, you could set its view to this xib base view, then populate the text view(s) with the proper text.
I'm creating an app to show a book by using UIPageViewController (to have the default page turn animation which is very nice)
I'm maintaining all the data related to each page in form of core data.
In my MyModelController.m file, under init method, I'm fetching all the data and initializing pageData array.
But the book that I'm going to show is huge one. So, is there any way to do something like dequeueReusableCellWithIdentifier so that only required pages will be loaded into memory?
Please correct me if my expectation is wrong.
Set the initial view controller using UIPageViewController's
-setViewControllers:direction:animated:completion:
Next, implement he following UIPageViewControllerDataSource methods:
– pageViewController:viewControllerBeforeViewController:
– pageViewController:viewControllerAfterViewController:
These methods allow you to provide the UIPageViewController with the view controllers before and after the current view controller.
This way you only keep a single view controller (and corresponding model data) in memory. I'm sure it does some caching behind the scenes, but if so, that would be freed when a low memory warning was triggered.
Instead of loading your entire data model in a single array, load only the required objects for the current view controller on-demand page-by-page inside your view controller representing a single page, or inside the two datasource methods mentioned above.
If you create an new UIPageViewController-based project in Xcode 4.2, you will see the default template has code demonstrating this.
Correct me if I'm mistaken, but I believe UIPageViewController, by default, only loads the next and previous page into the memory, so you shouldn't have to worry about memory management.
Not positive I understand your question, but it sounds like you don't want to have all of the content of your book loaded as page objects. Instead of loading the entire contents of the book in your init method only load the page being displayed, then when the user "turns" the page load the next, or previous, page based on the currently displayed page.
If you are using a PDF book, you can only load the desired page and pass to the view controller when these two methods are called
– pageViewController:viewControllerBeforeViewController:
– pageViewController:viewControllerAfterViewController: