Best way to implement UIPageControl? - objective-c

In my app I have a registration page for any new users. At the moment Im using UIPageControl on a view controller so that when a user swipes left a new set of textfields are displayed. I have it so that when the user swipes to the left the previous textfields are hidden. I don't think this is the best way of implementing UIPageControl. I would like to implement it in such a way that when the user swipes to the left the new text boxes slide in with the swipe instead of just appearing. Also when the user swipes back i have to make the previous text fields unhidden but then they don't keep the information that the user has already typed into them.
Any ideas of how to best implement UIPageControl or even the best way to implement a registration form like this?
Thanks a million!

If this is a march through a series of forms that the user must fill out in order, you could use instead a UINavigationController (which, indeed, is what is suggested by the Back button already in your interface)...
The real problem, however, seems to be that you are using UIPageViewController incorrectly: if the user is to be able to go back and forth between views and the information previously entered is to be present, it is up to you to use a different view controller for each view and to save the entered information when the user leaves a view controller and to restore it when the user summons that same view controller again.
This is something you would need to do no matter what implementation you choose, because a view controller can always be destroyed when its view is not being seen. Model-view-controller! It is up to you to maintain the model (the data) - do not rely on the mere view to maintain it for you.

Related

How come my uitextfield(s) keeps being disabled after model?

I made an app for my wife to track inventory. it has a couple of view controllers to enter a new item, display all items, search items, and display selected item. After switching through each view a couple of times (no particular order) all of the textfields become disabled (you cannot select them to change the value) across ALL of the view controllers. The buttons still work however. I have it setup so that when the user enters info into a particular cell, it saves it into memory so that if they switch views and then come back, the cells will get the data in the viewdidload method. Please Help!
*edit - I am using storyboard with a bunch of segues (i'm new to programming and self taught, so idk if this is the right way or not)... here is a pic of my storyboard
http://i.imgur.com/aT3PR0i.png
Ok, with a look at your storyboard, I think I see your problem. If your storyboard looks like somebody spilled spaghetti on it, it's not designed correctly. Specifically, it looks like you're going "backwards" (to controllers you've already been to) using segues -- that's not good. SEGUES ALWAYS INSTANTIATE NEW CONTROLLERS! So, if you go around in a circle a few times, you're adding more and more controllers to your project. To go backwards using segues, you need to use an unwind segue -- it's the only one that is an exception to the rule that segues always instantiate new controllers. The other ways to go backwards, without segues, are popping with navigation controllers, and dismissing modal controllers.
I can't really diagnose your immediate problem without a lot more information, but redesigning the storyboard using unwind segues would probably fix your problem.

iOS best practices to guarantee user has most recent updates to core data

For a simple note application, there is a table view controller with a fetchedResultsController that has a list of saved notes in core data. The user can either click the + button to add a new note or click on one of the records in the table view to edit an existing note. In either case, a modal view controller with a text view shows up.
I want to save as the user types each letter, so in textViewDidChange I am updating Core Data. If the user types too fast, the core data saves hang. I recently added code to add the updates to NSOperationQueue which was an idea taken from here:
How to implement work queue in iOS where only newest request is handled? and that has helped somewhat.
Here's the problem I need help with. Let's say the user types an update in the textView, then pushed Done to return to the table view controller, and then clicks on the same note to edit the note again before the original update was refreshed in the table view. The user is presented with a textView that has the old data. The update is not there. If the user goes back to the table view and edits the note again, the latest updates show.
What are some approaches to consider, or how could I attempt to fix this issue? I want the textView to always show the latest updates even if user is switching back and forth from the textView and tableViewController faster than a user should ;)
You don't need to save the context everytime the user adds a character, do it only when he finishes adding the note, or at least when the textfield loses its focus (first responder resigns). There's really no point in doing it everytime he taps. Saving the context is a pretty expensive operation.
Maybe try saving all of the changes at once in:
- (void)viewWillDisappear:(BOOL)animated
Instead of constantly saving as the user types, which is a bit redundant.
If the user goes to their home screen, then save the changes in
- (void)applicationDidEnterBackground

Cocoa-Touch: How to Change View After Input Validation?

I have a single-view application that takes in a username and a password and validates it with the server. After the credentials are validated, I would like the application to go to a different view, which will show some other data.
I only know how to switch views when I have a button (that is, by dragging it to the secondary view and selecting what kind of segue I want to use). But how do I change the view after the credentials are validated?
To give you a more clear idea, here is how my app currently functions:
Text is entered into two fields. Pressing the "Login" button (or the 'done' button on the keyboard) calls a method that validates the entered credentials. If the credentials are valid, then the add should move on. Otherwise, it will pop up a notification saying that the credentials are invalid.
I have everything completed and working. I just need to know how to change the view in the validation method after the given credentials are validated.
There are a number of ways to achieve this; the technique you choose should depend on if you want the validating view controller to "stay around" after you move on. If you want it to stick around, you can actually do it in much the same manner as your storyboard segues from buttons.
In the storyboard, ctrl-drag from the first (validating) view controller to the second to create the segue. Select the segue and use the inspector panel to give it an identifier. Then in your code in the validating view controller, you can do something like this:
[self performSegueWithIdentifier:#"validCredentialsSegue" sender:self];
If you want the originating view controller to "go away", you must look into the architecture of your application flow. Perhaps you want a master view controller "above" the credential's one that is notified via delegation of the successful login and it decides what to do (maybe it's view is the destination view anyway...). Otherwise, I think in the old days people fussed around with setting the window's rootViewController property. I'm confident there are better techniques, though.

add a subview to a not-showed uiview

I'm dealing with a weird problem: I've got a UIViewController to handle a list of items to download via inapp purchase.
When a user choses the product to buy, all the purchase flow begins. At this particular moment, I push a UILabel and a progress bar to display the current state of the download.
If, before that, a user choses to go in another part of the application (i.e. by tapping an item form the tab bar menu ), the application continues the purchasing process from there (that is reduced down to saying yes to a couple of dialog boxes and inputing the itunes store account credentials).
The process (that is attached to a background thread) runs smoothly till the end of it, but if the user comes back to the store view the UILabel and the progress bar are not show, I mean, they are initialized and running but they're not visible.
Is there a right way to behave in that circumstance?
Do I have to force the refresh of the view, or do I have to remove'em from the superView and push'em back again?
thank in advance,
hope I'd be clear enough, otherwise don't be afraid to ask, I'll be glad to
explain myself in a more deep and clear way.
-k-
Without a code it is difficult to give you the exact solution.
A possibility is that when you moved out from the original UIViewController the system did unload the view on that controller. It is possible that with this unload the progress bar and label were not destroyed (because over-retained by your view controller or not nil-ed in the viewDidUnload method) but when you entered in the view controller again the view was reloaded from scratch (typically from the nib) with new progress and labels.
So it is correct that you retained the progress bar and label (even if there are better ways to achieve the same result) but you must add them to the view controller view in the viewDidLoad method. A typical way to do this is to store a "active" progress bar in a dictionary and when the view is reloaded from the nib it must be added to it. As soon as the download finish you can remove the progress from both the dictionary and the view. There are other ways to accomplish the same result, so my suggestion is just to give you an idea.
So in order to see if my answer is correct, you must check the viewDidUnload method, add a breakpoint on it and see, once it has been triggered and when you come back to your original view, if the progress bar has disappeared or not.
Hello Holographix u havnt posted any code so it would be difficult to tell
well it seems like the object of Uilabel and progress bar are getting released the time u comes back to the view.

Delay navigationController to pop detailView of UITableView

Im looking for some help regarding to put a save like confirmation if some changes where made to a UITextField and UISegmentedControl.
Can I prevent the UINavigationController from pop the view? And then pop based on buttons in a AlertView?
I use the UITextField and UISegmented control to POST data to a webservice.
I perhaps need to use a modalView for this? but wanted first to see if someone have another idea, because I would like to keep navigation clicks down if possible.
Any suggestions for this?
Thanks,
Why not just using a UIAlertView?
EDIT: On second thought, and re-reading your question + comment, I would recommend to use a Modal View with classics OK/Cancel buttons + a UIAlertView(s) for confirmation(s). (UIAlertView "poping" on OK/Cancel is easy to do via UIAlertViewDelegate)
That's what Modal views are for, block UI until some user action has been completed. Like a form. This is how I do all my forms, and how Apple does (just look at the create mail screen for an example, or any form of iOS apps)
Adding a "Magical" action requiring user interaction on the back button of a navigation controller is bad in terms of user experience, if you hit back, you expect the view to pop, nothing else. I would then be surprised if Apple SDK even allows to cancel that event...
You can do what you would like without the need of a modal view.
First, you can use your text field's UITextFieldDelegate to set a flag in your controller when the field content is modified. You can reset this flag when the data is sent out.
Then you could override your UIViewContorller's viewWillDisappear to show an alert to the user in case new data have not been posted at the moment the view is going to disappear and give him the possibility of sending it to the server. This method will be called when you move to a different controller in your navigation UI, and you will not have a chance to "reject" the operation.