0

I am attempting to read the plist dictionary below into cells of a UITableView. I want to create a subview for each of the strings contained in the array denoted by the ArrayKey like:

Row1: | myString1 |
Row2: | myString2 || myString3 |

I've used fast enumeration to read the dictionary, but I can only successfully read the first string in each array:

    CGFloat constant = 0;

    for (NSArray key in [dictionary objectForKey:@"ArrayKey"]) {


        UILabel *label = (UILabel *)cell; 
        label.text = (NSString *)key;
        label.frame = CGRectMake(0 + constant, 0, 30, 30);

        constant = 20 + CGRectGetMaxX(label.frame);
        }

I'm missing the subview piece. And I'm puzzled why if I add an NSLog of the fast enumeration, the output will show all strings in the array, but I can only display the first (ie myString1 in one row and myString2 in a second row without myString3).

<dict>
    <key>TitleKey</key>
    <string>myTitle1</string>
    <key>ArrayKey</key>
    <array>
        <string>myString1</string>
    </array>
</dict>
<dict>
    <key>TitleKey</key>
    <string>myTitle2</string>
    <key>ArrayKey</key>
    <array>
        <string>myString2</string>
        <string>myString3</string>
    </array>
</dict>
L-1987
  • 5
  • 2

1 Answers1

0

Mystifying why this code is working at all. I am sure you are posting only partial code.

  1. UILabel *label = (UILabel *)cell; will create a pointer to exactly the same item cell and overwrite whatever is there.
  2. If dictionary is nil then [dictionary objectForKey:@"ArrayKey"] must cause a crash.
  3. id key should be NSString *key in order to assign it to label.text.
  4. You are not adding the label anywhere as a subview.

You need at least a [cell.contentView addSubView:label];.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • You're right it is only partial and I am a super beginner at this. I was hoping for help adding the subview. – L-1987 Aug 31 '11 at 20:04