Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't a Double value stored as Object in NSUserDefault is not reflected in UITableViewCell?
    text
    copied!<p>I am trying to store <code>Double</code> Value in <code>NSUserDefault</code> But though i am able to store it (as my NSLog value shows true value), when I tried to reload UITableView, its Cell value is not updated with current value in userdefault.</p> <p>This weird behavior happens only when i call my <strong><code>setUserDefaults</code></strong> method from delegate method of <code>UIAlertView</code></p> <p>Why such weird behavior happens??</p> <p>Here is my code:</p> <pre><code>- (void)setUserDefaults { NSLog(@"setUserDefault : empArray: %d, empCount: %d",empArray.count, empCount); NSMutableDictionary *empData = [[NSMutableDictionary alloc] init]; if (empArray.count&gt;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]; } </code></pre> <p>Delegate method of UIAlertView goes as below:</p> <pre><code>-(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]; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload