ios - NSMutableDictionary setValue:forKey failing sometimes -


I am using NSMutableDictionary to add 3 keys / values. The value is bool in a form of NSNumber. Then I have a table view that loads the data, if the cell is pressed, then the value changes from either to NO or vice versa.

It seems that when the cell is pressed the value changes properly, except for the last key / value in the dictionary

  NSMutableDictionary * modsDict; NSString * test = @ "test"; NSString * test1 = @ "test1"; NSString * test2 = @ "test2"; - (zero) tableview: (UITableView *) table view was SelectionRowAtIndexPath: (NSIndexPath *) indexPath {UITableViewCell * cell = [tableView cellForRowAtIndexPath: indexPath]; [Deselect tableview inevitably pyth: indexpath animated: yes]; NSString * key = [NSString stringWithFormat: @ "% @", [[modsDict allKeys] objectAtIndex: indexPath.row]]; If (cell.accessoryType == UITableViewCellAccessoryNone) {// Enable Cell.Setty Type = UITableViewCellAccessoryCheckmark; [ModsDict Set Value: [NSNumber Number for Whistleblower: 1] Key: key]; } Else {cell.accessoryType = UITableViewCellAccessoryNone; [ModsDict Set Value: [NSNumber Number With Bull: 0] For: Key]; }} - (zero) viewDidoad {% orig; ModsDict = [[NSMutableDictionary alloc] init]; [ModsDict Set Object: [NSNumber Number: W.Bool: 0] KK: Test]; [ModesDict Set Object: [NSNumber Number Vithubles: 0] for KA: Test 1]; [ModsDict Set Object: [NSNumber NumberWindle: 0] for KA: Test 2]; ... // init tableview} - (zero) someMethodThatIHookTo {NSNumber * val = [modsDict objectForKey: test2]; If ([val boolValue] == yes) {// do something} // it works for test and test1, but this ball for test2 = lol = [[modsDict objectforki: test2] boolValue]; If (qualified) {// something} some other {} / / always is always called if ([[modsDict ItemFork: test2] boolValue]) {} else {} // If the statement is always correct, then sometimes It does not even go}  

These are the three ways that I tried to get value from NSDISION [NSNumber Number Powerful: 0/1] Because if I use No / Yes then This will also return as a yes even if no experiment has been done.

No matter how many times I have pressed the cell, the result is by 3 ways ...

How can I solve it?

> Please note that I am using it on TOOS, get mobile as a tweak

I think that you might have read the documentation a bit harder to read

What does the document say for allKeys :

Discussion
The order array of elements has not been defined.

With this in mind, do you think the following piece of code will be produced?

  [[modsDict allKeys] ObjectAtIndex: indexPath.row]  

This is probably why you are searching for superstitious beliefs like:

I am doing [NSNumber numberwithbool: 0/1] because if I use No / YI will return it as Yes, even if NO is used.

For the record:

  • It's just idiocy @YES and @NO ;
  • [NSNumber numberwithbooth: 0] and [NSNumber numberwithbool: no] will return not only the number of the same value but NSNumber Returns the numbers with the same identical identities due to the special case related to the booleans. Yes / OK for non-zero

Fix your code with an undefined order to stop the notion of some order, perhaps just use one array, because it is unclear whether you are using a dictionary anyway Why are you using


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -