Double
の値をNSUserDefault
に保存しようとしていますが、NSITableViewを再ロードしようとしたときに、NS値が実際の値を示すように格納できましたが、そのCell値がuserdefaultの現在の値で更新されません。NSUserDefaultにObjectとして格納されたDouble値がUITableViewCellに反映されないのはなぜですか?
この奇妙な振る舞いは、このような奇妙な行動が起こるのはなぜ私がUIAlertView
のデリゲートメソッドから私のsetUserDefaults
メソッドを呼び出したときにのみ起こります? UIAlertViewの
- (void)setUserDefaults
{
NSLog(@"setUserDefault : empArray: %d, empCount: %d",empArray.count, empCount);
NSMutableDictionary *empData = [[NSMutableDictionary alloc] init];
if (empArray.count>1)
empData = [empArray objectAtIndex:(empCount-1)]; // because empCount starts from 1. and empArray[0] = empCount 1
else
empData = [empArray objectAtIndex:0];
[userDefault setObject:[NSString stringWithFormat:@"%.2f",[empData objectForKey:@"salary"]] forKey:@"salary"];
NSLog(@"setUserDefaults: salary=%.2f",[[empData objectForKey:@"salary"] doubleValue]);
[empData release];
[self.tblView reloadData];
}
デリゲートメソッドは、以下のようになります::ユーザーのデフォルト値を設定するときは、doubleValue
を使用していない
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger) buttonIndex
{
if (alertView.tag == 1) // btnRemoveEmpPressed.
{
if(buttonIndex==0)
{
NSLog(@"buttonIndex 0");
}
else
{
NSLog(@"empRemovedPressed OK, buttonIndex 1, empArray Count %d, empCount %d",empArray.count, empCount);
// [empArray removeObjectAtIndex:(empCount)];
empCount -= 1;
lblTitle.text = [NSString stringWithFormat:@"Employee %d",empCount];
[self setUserDefaults];
}
// [tblView reloadData];
}
else if (alertView.tag == 2)
{
if (buttonIndex==1)
{
[self resetUserDefaults];
empCount = 1;
[empArray removeAllObjects];
lblTitle.text = [NSString stringWithFormat:@"Employee %d",empCount];
}
}
}
cellForRowAtIndexPathコードも表示できますか? – zakishaheen