views:

212

answers:

1

I seem to have a problem understanding how to conditionally test a boolean value loaded from a .plist to a mutablearray. I simply dont understand what i am supposed to do and continue to receive an error: Passing argument 1 of 'numberWithBool:" makes integer from pointer without a cast. any help understanding this is appreciated!

heres my code:

if ([NSNumber numberWithBool:[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"]]) {
 cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IsSelected.png"]];
}
A: 

The method numberWithBool: of NSNumber expects a boolean (BOOL) as its parameter.

[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"]] apearantly returns something other than BOOL.

To cast either an NSNumber or an NSString object to a boolean, you can use the boolValue method.

So, try and do the following:

if ([NSNumber numberWithBool:[[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"] boolValue]]) {
        cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IsSelected.png"]];
}
nash
thx for your help. i knew i wanted to cast but was struggling with syntax. the odd thing i found that when my dictionary stores a YES for some reason i am testing in "IF" statement with a "!" NOT. it works but seem opposite. but for now i am going with it. thanks!
Abbacore