Disclosure Indicator and Detail Buttons on same table

Discussion in 'iOS Programming' started by StevenHu, Dec 31, 2009.

  1. StevenHu macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #1
    I have a table in which one cell goes to another table, and thus uses a disclosure indicator icon. All the rest of the cells use the detail disclosure button.

    How do I specify the one disclosure indicator for the one cell when the method uses *indexpath for all the cells? Am I supposed to use a switch for this situation?

    Thanks,
    Steve
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    You could just use an if statement. If that cells text matches what your looking for then set the cell indicator. If not set it to the other indicator.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You could. A simple if might even suffice. And don't forget that the indexPath contains both unique section and row for each cell.
     
  4. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #4
    OK, so I'll do an if/else after the "if (cell == nil)" line.
    Hmmm... wrong syntax when attempted. I'll keep trying.

    Thanks!
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Just to be clear, you'll probably want to be doing the logic outside of that if statement, since it only executes when a cell is not being reused (i.e. needs to be instantiated). You're gonna want to make sure you are setting the right indicator for reused cells as well. Otherwise, you may find cells with the wrong indicator appearing.
     
  6. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #6
    If I were you I would set it right before i set the text in the cell.
     
  7. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #7
    I can't seem to get the if() part right. if(indexPath == 1) generates a warning and doesn't make a difference with the icons. Don't know what syntax to use to check for the view controller name.

    Thanks,
    Steve
     
  8. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #8
    You have to get the row out of the indexpath first.
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Correct. That's because indexPath is not an integer, it's an NSIndexPath.
     
  10. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #10
    This helped. I used

    Code:
    NSUInteger row = [indexPath row]; 
    if (row ==1)
    The icon changed on the side as I wanted, but the above generated two warnings. The first line was "initialization makes pointer from integer without a cast," and the second line was a "comparison between pointer and integer."

    I'm going too fast! Got to slow down and think it through!
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Please do! :D
     
  12. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #12
    OK, all I needed was

    Code:
    if (indexPath.row ==1)
    No warnings or errors and the icons appear correctly!

    Thanks!
    STeve
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    P.S.

    The above code won't generate any warnings. But it will generate those if it's:
    Code:
    NSUInteger *row = [indexPath row]; 
    if (row ==1)
    Make sure the code snippets you are including in your posts are the same as in your code. Otherwise, you are just going to confuse those trying to help you.

    P.P.S. Please use
    Code:
     tags.
     
  14. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #14
    Sorry about that, Dejo! My Mac Mini is not connected to the Internet here, so I scoot to the PC and post from there.

    Thanks,
    Steve
     
  15. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #15
    An alternative might be to put all that logic in the "(if cell == nil)" statement, but then use different reuse identifiers for each different case.
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    Agreed. That's a suitable alternative.
     
  17. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #17
    That's out of my knowledge zone, unfortunately. I'm still learning as I go!

    Thanks,
    Steve
     
  18. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #18
    A handy alternative to hard-coding these numbers is to add a Boolean to your table data. If you are using an array of dictionaries to populate your table, you can add a Boolean to certain "rows". Then, instead of checking to see if the current row corresponds to "1", you can check the appropriate Boolean.

    This will just make it easier if you ever have to rearrange your table data. Using a PLIST is just a matter of dragging things around without having to go back to this line and change the index of the special cell.
     

Share This Page