Editable Table Views

Discussion in 'Mac Programming' started by Duke Leto, Apr 9, 2008.

  1. macrumors regular

    Joined:
    Mar 17, 2008
    #1
    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.
     
  2. macrumors member

    Joined:
    Oct 26, 2007
    Location:
    [[NSLocation alloc] initWithCity: Chicago]
    #2
    Check out the UI Sampes and the other samples they are very good..
     
  3. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #3
    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?
     
  4. thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #4
    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! :)
     
  5. thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #5
    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.
     
  6. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #6
    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:

    Code:
    - (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:

    Code:
    UISimpleTableViewCell *cell = [[[UISimpleTableViewCell alloc] initWithFrame:CGRectZero] autorelease];
    
    cell.text = @"Howdy!";
    return cell;
     
  7. macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #7
    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.
     
  8. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #8
    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.
     
  9. thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #9
    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.
     
  10. macrumors member

    Joined:
    Aug 6, 2006
    #10
    Yeah, I'd certainly look at UIShowcase for this. They've got pretty much everything you'll need there.
     

Share This Page