Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have an NSMutableDictionary which has key as a name, and UIImage as an object. In my view controller, I have a custom cell which displays image to the left and name to the right. Basically, something like UITableViewCellStyleDefault.
When I have one image and one name per row, everything is ok. Now I want to have two images and two names, per one cell, but from that one dictionary.
How to do that?
Post edited by djalfirevic on
And thus I clothe my naked villainy; with old odd ends stolen forth from holy writ; and seem a saint when most I play the devil.
Do you now know what I want to do? I want to take two objects in one iteration, and store objects/keys to one cell, etc. Of course, if I have 17 object/key pairs, I want to store them in 9 rows. 8 rows would have 2 pics and 2 labels, and the last would have 1 image and 1 label, and other image/label would be empty.
And thus I clothe my naked villainy; with old odd ends stolen forth from holy writ; and seem a saint when most I play the devil.
Do you now know what I want to do? I want to take two objects in one iteration, and store objects/keys to one cell, etc. Of course, if I have 17 object/key pairs, I want to store them in 9 rows. 8 rows would have 2 pics and 2 labels, and the last would have 1 image and 1 label, and other image/label would be empty.
The other poster has a much better idea. Save both text strings and both images in a single dictionary. Save that dictionary in an array at the indexPath.row. (Or create an array of custom data objects where the custom data object has properties for all the attributes you need for a cell in your table view.)
You COULD use two array indexes for each cell, but you're going to drive yourself crazy doing it. You would need to use code like this:
int dict1Index =indexPath.row*2; int dict2Index =indexPath.row*2+1;
You would then need to make sure that you create and maintain 2 array entries for each REAL entry in your table view.
Again, I strongly advise against this approach. You're going to confuse yourself, cause problems that are hard to debug, and confuse the hell out of anybody else who tries to look at/maintain your code.
EDIT: Even worse, you will have code that is completely inflexible. If you later need to add a third text field, but not a third picture, how would you do that? What about a checkbox, slider, or segmented control? Are you going to go back and change your data structures to save THREE data elements per table view cell? What if you only want to add one more thing, not two/three? it's just a messy, ugly way to store your data. Bad design, bad idea. Don't do it.
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Replies
New app - See screenshots and details at www.globaclock.com.
If you want to
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDo you now know what I want to do? I want to take two objects in one iteration, and store objects/keys to one cell, etc. Of course, if I have 17 object/key pairs, I want to store them in 9 rows. 8 rows would have 2 pics and 2 labels, and the last would have 1 image and 1 label, and other image/label would be empty.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe other poster has a much better idea. Save both text strings and both images in a single dictionary. Save that dictionary in an array at the indexPath.row. (Or create an array of custom data objects where the custom data object has properties for all the attributes you need for a cell in your table view.)
You COULD use two array indexes for each cell, but you're going to drive yourself crazy doing it. You would need to use code like this:
You would then need to make sure that you create and maintain 2 array entries for each REAL entry in your table view.
Again, I strongly advise against this approach. You're going to confuse yourself, cause problems that are hard to debug, and confuse the hell out of anybody else who tries to look at/maintain your code.
EDIT: Even worse, you will have code that is completely inflexible. If you later need to add a third text field, but not a third picture, how would you do that? What about a checkbox, slider, or segmented control? Are you going to go back and change your data structures to save THREE data elements per table view cell? What if you only want to add one more thing, not two/three? it's just a messy, ugly way to store your data. Bad design, bad idea. Don't do it.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome