views:

34

answers:

2

In our iPhone app we have a controller 'AddViewController' which shows a data entry screen to add a new entry. It includes Save and Cancel buttons.

Currently if a user enters nothing at all in any of the text fields and presses Save the app crashes. (Yes I know it's silly for someone to do this, but hey just covering off on everything)

How to handle the save scenario above so the system doesn't crash or save a blank record and just returns gracefully to the previous page like Cancel?

+3  A: 

You should check each field for valid input, and then display an alert view if anything is invalid.

If you don't want to alert the user and just return without saving a blank document, then you should still check for valid input and only commit data that is valid.

Jasarien
Could you provide me some simple sample code of how to popup on validation? (It'll save me a bunch of stuffing around with apple refs)
Evolve
Evolve: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIAlertView_Class/UIAlertView/UIAlertView.html And keep this in your bookmarks: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIKit_Framework/
Peter Hosey
+3  A: 

What I do is disable the SAVE button until I have something to validly save. Shows the user when they can do it and does not annoy the user with an alert box. I have a validation function that enables the save if all good triggered after each field changes.

Hiltmon
It's also a good idea to have a cancel button, so as to not keep the user in the screen and forcing them to enter data (unless the form is mandatory, of course).
Jasarien