List/Detail Editing

Discussion in 'iOS Programming' started by Chetmun, Aug 14, 2009.

  1. Chetmun macrumors newbie

    Joined:
    Aug 13, 2009
    #1
    What's the best way to have a list of text items, tap on one and be able to edit it? How about going to a detail view? But then how do you get your change back into the UITableView?

    I suppose this could all be done with SQL or CoreData but since the UITableView is based on an array, can we just edit that element of the array and reset the table view?

    Eventually I want the data to be persistent so I'll probably go with CoreData or SQL but for now I just want to go from a list to details, edit the details, and go back to the list.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Usually, something like this is done by having a UITableViewController within a UINavigationController. Then, when the detail view is requested by tapping on a row of the table, pushViewController is called and the new view is presented, with a navigation bar still at the top and a Back button automatically included. I'd suggest checking out one of the tableView-related Sample Apps.
     
  3. Chetmun thread starter macrumors newbie

    Joined:
    Aug 13, 2009
    #3
    Thanks, dejo. Actually the navigation is not the issue for me. It's the data itself. I can get the data from the table row to be in a text field on the detail view. But if that text is edited, how do I get it back into the table view?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Update the data source and reload the table.
     
  5. Chetmun thread starter macrumors newbie

    Joined:
    Aug 13, 2009
    #5
    OK, but the data source is just an array created and populated in the class with the table view. I passed the array and the tapped cell row index to the detail view and that's how I get the text into the text field on that view.

    Objective-C is laughing at me. I can't even get the editing text back into that array! Assuming I figure that out, I suppose I would have to go back through the array and reset all the cells a la tableView: cellForRowAtIndexPath. But I wouldn't know in which method/class to put that code.

    Course, maybe I should just do this a different way. Is there some kind of "iPhone Way" of doing this sort of thing? I'm not finding anything in my searching so far. Everybody talks about having the table and tapping to a detail view but nobody says anything about editing that data.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Just reload the data for the UITableView. cellForRowAtIndexPath will get called automatically for all visible rows.

    It really sounds like you are trying to bite off more than you can chew at this point. I'd suggest it's time to step back from the real coding, go (re)learn the basics of Objective-C and iPhone development, and then return to this once you feel you have a better handle on those.
     
  7. Chetmun thread starter macrumors newbie

    Joined:
    Aug 13, 2009
    #7
    Thanks, I just don't have the time to learn this stuff right. I wish I could step back but I keep getting things thrown at me and I keep hitting bumps due to my lack of understanding of so many things about Objective-C and the iPhone Way. I've been doing mostly Java on Windows for the last several years.

    Usually a code snippet or two is all I need because I get stuck on syntax and the frameworks. When forum folk say where those snippets go, I get a clue that I can build on and getting a little thing to work usually translates to larger things.

    I appreciate your comments (and your help!) but this is how I have to operate right now. Thanks again.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Ok, understood. It's just that you are probably going to find that most posters in the iPhone Programming forum are willing to give you guidance but they will be rather reluctant to just give you out-right solutions. Because then it is just you using their experience to do your coding for you. At least, IMHO. :)
     
  9. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #9
    If so, then exactly why should we find the time to give you the right answers? (as opposed to say, silly ones, which some might find more entertaining :)
     
  10. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #10
    I don't think that's what he's asking. I suspect he just wants somehing like this:

    Simplest way; make your data array a mutable array.
    Add a property to your detail view controller: NSMutableArray *dataArray;
    And NSInteger selectedIndex;
    Set them before you push the detail viewControllerband then when they edit the text in the detail editfield you have access to the table view controllers data array and can change it there.
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Perhaps not. But that was my understanding based on this comment:

    By giving them a code snippet or two and instructions on where to put them, you've probably just supplied them with the solution. At least, I think you would. I get the feeling that the pseudo-code you provided would not be detailed enough for the OP since they don't have time to figure out how to translate that into actual code. I could be totally off-base here, though, so, if I am, my apologies.
     

Share This Page