I woud like to implement some editing mechanism for an iPhone application, that is I want the user to be able to edit an instance of my model. The model contains two types of data: The first is just an NSString where the user can write virtually anything he likes. The second one is a selection where he is able to pick one from some given values.
My goal is to adapt the way Apple uses in its Settings app. For example, in the Settings app Apple presents a modal view to enter the information for mail accounts. The user has to enter strings for name, address, password, ... and he has to choose from one of four options in the authentication methods of the SMTP server.
Do I have to implement this all myself? Just presenting the data in a table view using UITableViewCellStyleValue2
cells and enabling editing gives me only the chance to add or remove entries. However, this is clearly not what I want.
If I indeed do have to implement it myself, what is the best practice? Creating custom cells with a Label and a UITextField
is no problem, but I would need about 25 of those cells in total. I see that there is no chance to be notified if a cell is moving off the screen, so how do I best save the data the user entered?
My current idea is to "bind" the UITextField in the custom cell to a key path in my model. I.e. I supply the key path to update to my custom cell and from my controller I call [model setValue:cell.textField.text forKeyPath:cell.keyPath];
on receiving a UITextFieldTextDidChangeNotification
. So is updating the model for each key press a good idea? I doubt that this performs well. For the multiple choic开发者_高级运维e cells, I added a UINavigationController to my modal view.
Are there any better ideas?
I eventually solved the issue as I suggested myself above.
I present a navigation controller that shows a table view displaying my model using custom cells with a label and a text field. The delegate of all textFields is the UITableViewController which implements the UITextFieldDelegate
methods -textFieldDidBeginEditing:
and -textFieldDidEndEditing
. I supply a tag to the custom cells so I can set the according property of my model (SQLite database entry).
I tried that on an iPhone 3G and it performs reasonably well.
Thanks anyway!
精彩评论