PDA

View Full Version : Editable Table Views




Duke Leto
Apr 9, 2008, 06:34 AM
I am making an iPhone application and I know that you can edit the information. (press the edit button, every table view is different , then click on one and voila a keyboard/picker/whatever comes up for you to input data). What do I need to be able to do this. What kinds of classes and functions do I need, and what do they need to be able to do?

Thank you in advance for helping.



iphoneGuy
Apr 9, 2008, 07:15 AM
I am making an iPhone application and I know that you can edit the information. (press the edit button, every table view is different , then click on one and voila a keyboard/picker/whatever comes up for you to input data). What do I need to be able to do this. What kinds of classes and functions do I need, and what do they need to be able to do?

Thank you in advance for helping.

Check out the UI Sampes and the other samples they are very good..

Littleodie914
Apr 9, 2008, 07:43 AM
There are lots of different way to implement a "edit" function.

Do you want to hit the edit button, then click on one of your TableView's rows and have it pull up an edit window for the object in that row?

Or are you looking for a way to place editable text fields into a table view?

Duke Leto
Apr 9, 2008, 03:41 PM
I would want it to be that when you press the edit button you ca then edit the data in each text field. I recently downloaded the SQLite Books sample code, and I am trying to sift out what I need to know, but if I could get some help here, it would push me forward! :)

Duke Leto
Apr 10, 2008, 06:56 PM
I have watched the tutorial on making the edit button that goes into editMode. I have realized a bit better how this works. My new question here is how would I go about adding cells or editing text in a text field... not that much different of a question I realize, but I do not want this thread to drown unanswered.

Littleodie914
Apr 11, 2008, 10:33 AM
I have watched the tutorial on making the edit button that goes into editMode. I have realized a bit better how this works. My new question here is how would I go about adding cells or editing text in a text field... not that much different of a question I realize, but I do not want this thread to drown unanswered. Could you be a bit more specific? To edit text in a textfield, you can usually just use the setText: method.

To add a cell to a table view, (I assume this is how you mean it) you just need to implement the delegate method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

And return a cell that includes the data you want to display. A good place to start is like so:

UISimpleTableViewCell *cell = [[[UISimpleTableViewCell alloc] initWithFrame:CGRectZero] autorelease];

cell.text = @"Howdy!";
return cell;

lucasgladding
Apr 11, 2008, 12:09 PM
I'm still not sure how much detail I want to get into on the forum with the NDA in effect, but here is how I approached editable text fields.

- use custom UITableViewCell with a UITextField as a subview
- override UITableViewCell setSelected: to call makeFirstResponder on the UITextField
- use the view controller viewDidAppear and viewDidDismiss to get the strings from the UITextFields

This is a somewhat different approach than the SQL example, but it works very well for me and requires very little work to implement. That said, I got a few ideas from the example that really helped.

BTW: Offhand, I think you only need the data source methods of UITableView to get the editing functionality.

Littleodie914
Apr 11, 2008, 02:34 PM
I'm still not sure how much detail I want to get into on the forum with the NDA in effect, but here is how I approached editable text fields.

- use custom UITableViewCell with a UITextField as a subview
- override UITableViewCell setSelected: to call makeFirstResponder on the UITextField
- use the view controller viewDidAppear and viewDidDismiss to get the strings from the UITextFields

This is a somewhat different approach than the SQL example, but it works very well for me and requires very little work to implement. That said, I got a few ideas from the example that really helped.

BTW: Offhand, I think you only need the data source methods of UITableView to get the editing functionality.Yea, I think that method should also work. For my cells, I did the following:

- use custom UITableViewCell with a UITextField as a subview (like you)
- override UITableViewCell willSelectRowAtIndexPath (or something like that) and return -1, so that the actual cell will never be selected
- make sure that the textfield's bounds are the bounds of the tableviewcell, so that any touch on the cell begins the editing for the textfield

Then, I just maintain a reference to the textfield, and use [textField text] to get the value that the user typed in.

Duke Leto
Apr 12, 2008, 09:34 AM
Thank You! I just wanted an idea of what I needed to do, and I think that gave me a push! Now a skill I need to work on is properly phrasing questions. I seem to have trouble putting things into words.

maxjg
Apr 13, 2008, 02:53 AM
Yeah, I'd certainly look at UIShowcase for this. They've got pretty much everything you'll need there.