UISwitches の NSArray があります。キーが NSNumbers であり、オブジェクトが NSString オブジェクトの形式の BOOL 値である NSDictionary を別に持っています。私がやりたいのは、UISwitches の NSArray を反復処理し、タグ値が NSDictionary 内のキーの 1 つであるかどうかを確認し、一致が見つかった場合は、UISwitch の有効なプロパティをキーの対応するオブジェクトに設定することです(NSString から BOOL に変換した後)。
私のコードは次のとおりです。
for (int i=0; i<[self.switchCollection count]; i++) {
UISwitch *mySwitch = (UISwitch *)[self.switchCollection objectAtIndex:i];
if (tireSwitch.tag == //this has to match the key at index i) {
BOOL enabledValue = [[self.myDictionary objectForKey:[NSNumber numberWithInt://this is the key that is pulled from the line above]] boolValue];
mySwitch.enabled = enabledValue;
}
}