ここで何かが欠けています。それほど難しいことではないことはわかっていますが、理解できません。私は辞書のリストを持っています。それは可変配列にロードされ、それが私のtableViewに入力されます。
plist サンプル:
<?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">
<array>
<dict>
<key>title</key>
<string>entry1</string>
<key>checkedState</key>
<string>NO</string>
</dict>
<dict>
<key>title</key>
<string>accessoriesImage</string>
<key>checkedState</key>
<string>NO</string>
</dict>
<dict>
<key>title</key>
<string>activationCharge</string>
<key>checkedState</key>
<string>NO</string>
</dict>
そして、それらの辞書の値にアクセスしようとしていますが、混乱しています。
これが私の初期化です:
static NSString *kTitleKey = @"title";
static NSString *kCheckedState = @"checkState";
@interface ViewController ()
@end
@implementation ViewController
@synthesize attributesTableView, attributesArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nil bundle:nil];
if (self) {
NSString *attributesFile = [[NSBundle mainBundle] pathForResource:@"attributesPlist"ofType:@"plist"];
attributesArray = [[NSMutableArray alloc] initWithContentsOfFile:attributesFile];
}
return self;
}
関連するビットにスキップして、tableView セルに次のものを入力します。
cell.textLabel.text = [[attributesArray objectAtIndex:[indexPath row]] valueForKey:kTitleKey];
didSelectRowAtIndexPath の後半で、これらの辞書の値をチェックしようとしていますが、そこで失敗しています。
例:
if ([[attributesArray valueForKey:kTitleKey = @"All"] valueForKey:kCheckedState = @"YES"]) {
[attributesArray setValue:kCheckedState = @"NO" forKey:@"All"];
[attributesArray setValue:kCheckedState = @"YES" forKey:[[attributesArray objectAtIndex:[indexPath row]] valueForKey:kTitleKey]];
次のエラーが表示されます: valueForUndefinedKey:]: このクラスはキー YES のキー値コーディングに準拠していません。
間違ってアクセスしていることはわかっていますが、変更可能な辞書で満たされた変更可能な配列を使用しているときにそれを行う方法がわかりません。