UITableView / array question

Discussion in 'iOS Programming' started by larswik, Nov 9, 2012.

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I have a tableivew that is populated from an array. Each index of the array is an NSDictionary with a list of food a person has eaten that day. As I am testing this part of my app over the last couple of weeks I am noticing that I am having to scroll down the list for quite some time to get to the current day.

    I decided it is best to show the current day at the top of the list in stead of the bottom. Is the best approach just to invert the array that the tableView uses as it's data source? So the last object becomes the first object and so on?
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Having the order of the data model be the same as the order of the rows in the table makes things simpler. Simple is good. Obviously it would be possible for you to write a rowDictionaryForIndexPath: method that would have whatever logic is needed to get the row dictionary but simpler is better.
     
  3. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    Yes, that is what I thought. So if I invert the array first, before I use it for the data source. Index.row, the 0 row would then match up with the 0th index of the array. Since the array is now inverted the last array index is now the first array index. This seems to be the simplest thing I could think of.

    Thanks!
     
  4. macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
  5. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    Huh, So instead of adding the dict to the end of the Array like I am doing, which I would have to invert. Insert the dict to the beginning of the array.

    This is why I like this board. I didn't even think of that.

    Thanks!
     

Share This Page