Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
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
 

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
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.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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?
You could. A simple if might even suffice. And don't forget that the indexPath contains both unique section and row for each cell.
 

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
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.

OK, so I'll do an if/else after the "if (cell == nil)" line.
Hmmm... wrong syntax when attempted. I'll keep trying.

Thanks!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
OK, so I'll do an if/else after the "if (cell == nil)" line.
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.
 

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
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
 

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
You have to get the row out of the indexpath first.

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!
 

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
OK, all I needed was

Code:
if (indexPath.row ==1)

No warnings or errors and the icons appear correctly!

Thanks!
STeve
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
P.S.

Code:
NSUInteger row = [indexPath row]; 
if (row ==1)

...but the above generated two warnings.
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.
 

StevenHu

macrumors member
Original poster
Sep 3, 2009
80
0
Southern CA
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
 

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
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.

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.
 

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.