0

我有一个带有 WishInfoTextView 的自定义 UITableViewCell,它只是 UILabel 的一个子类。

 static NSString *CellIdentifier = @"Cell";
 NSMutableDictionary* item = [myWishes objectAtIndex: indexPath.row];

WishTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if( cell == nil ) {
    cell = [[WishTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    [cell setSelectionStyle: UITableViewCellEditingStyleNone];
    [cell setWishInfo: item];
}    

WishInfoTextView* infoText = (WishInfoTextView*)[cell viewWithTag: kTableInfoText];
infoText.text = [item objectForKey:@"name"];

NSLog(@"\nTaggedText: %@\nNormalText: %@", infoText.wishName, [item objectForKey:@"name"]);

唯一的问题是我有重复的单元格。我读了一些关于设置标签的东西。但是,如果我通过他的标签访问我的标签,则没有任何变化。

4

1 回答 1

1

You're using objectForKey@"name" every time you want a cell. So you will always get the same thing. If you have an array of strings, use something like [arrayName objectAtIndex:indexPath.row] in order to actually get different values.

For example, when I populate a table from an array I use

NSArray *nameSection = [appD.data objectForKey:key];
cell.textLabel.text = [nameSection objectAtIndex:indexPath.row];

appD.data is gotten by

NSString *DataPath = [Path stringByAppendingPathComponent:@"Primary.plist"];
NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:DataPath];

Where Primary.plist is

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>First type</key>
    <array>
        <string>object1</string>
        <string>object2</string>
        <string>object3</string>
    </array>
    <key>Second type</key>
    <array>
        <string>thing1</string>
        <string>thing2</string>
        <string>thing3</string>
    </array>
</dict>
</plist>
于 2012-07-03T14:58:59.737 回答