Assignments using objectAtIndex
Why would this work:
firstItem = @"Some value";
And this result in an error when I try to acces开发者_StackOverflow中文版s the NSString firstItem property:
NSArray *values = [dict allVaues];
firstItem = (NSString *)[values objectAtIndex:0];
From the .m:
@synthesize firstItem;
From the .h
NSString *firstItem;
@property (nonatomic, retain) IBOutlet NSString *firstItem;
NOTE: If I NSLog from the method I set this property it shows the correct values for the erring example, but later on the data is not available. I assume I need to set the values explicitly and not as references to my NSMutableDictionary that is out of scope. Any advice?
Your issue is you're not actually using the property. You're assigning the ivar directly instead. If you change your @synthesize
line to say
@synthesize firstItem=_firstItem;
then you'll notice that your code using firstItem
will no longer compile. That's a good sign that you're inadvertently ignoring the property accessors. You should be using self.firstItem = foo
instead.
精彩评论