TableView-IndexPath Question

Discussion in 'iOS Programming' started by jmerkow, Feb 7, 2011.

  1. jmerkow macrumors newbie

    Jan 20, 2011
    I have a number of objects in a table-view that rotate order after a button is pressed (object 0 becomes object @ end, object 1 becomes object 0 etc). I have this working now by having an index that carries the current index for the top of the queue, and programmatically get the object at 'i' according to the starting index. It is working fine, the order changes as I want. But I was looking at the indexpath class and it occurred to me that I may be able to modify the indexPath to achieve this same goal. And it may come in handy when I want to allow the user to reorder the objects. I looked it up online and it the results are vague. I wanted to see if this method was worth pursuing.

    P.S. I do not want to use a picker.
  2. cnstoll macrumors 6502

    Aug 29, 2010
    Typically you don't modify the IndexPath for a cell directly, you just use it to determine which cell you're going to modify in a TableView delegate method.

    I'm not sure what you're doing to make your cell rotation work, but it sounds like all you actually need to do is remove the last cell from the table and datasource, and insert it at the front of the table and datasource. It should even animate well if you use the built in tableview insert/animation methods.
  3. jmerkow thread starter macrumors newbie

    Jan 20, 2011
    The array that the cells are generated from are contained in a aggregated class (a GameState class) inside the view controller. I don't want the viewcontroller to have direct control over the array of objects inside. The GameState keeps track of the currentIndex, and it will return any object inside of it with reference from that currentIndex. i.e. if currentIndex = 4; and you want the object index = 2, it will return the object at index 6.

    I suppose I could re-factor so the top is always at 0, but I want the GameState object to keep track of the game, and all the view does is allow interaction and show the game.

    But, you answered my question, I do not want to modify the indexpath, typically you move the objects around, which is more or less what I am doing

Share This Page