objective-c having issues with an NSDictioary object
- by Mark
I have a simple iPhone app that Im learning and I want to have an instance variable called urlLists which is an NSDictionary
I have declared it like so:
@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>{
IBOutlet UIPickerView *pickerView;
NSMutableArray *categories;
NSDictionary *urlLists;
}
@property(retain) NSDictionary *urlLists;
@end
and in the implementation:
@implementation MyViewController
@synthesize urlLists;
...
- (void)viewDidLoad {
[super viewDidLoad];
categories = [[NSMutableArray alloc] init];
[categories addObject:@"Sport"];
[categories addObject:@"Entertainment"];
[categories addObject:@"Technology"];
[categories addObject:@"Political"];
NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", nil];
urlLists = [NSDictionary dictionaryWithObjects:objects forKeys:categories];
for (id key in urlLists) {
NSLog(@"key: %@, value: %@", key, [urlLists objectForKey:key]);
}
}
...
@end
And, this all works up to here.
I have added a UIPicker to my app, and when I select one of the items, I want to Log the one picked and its related entry in my dictionary.
-(void) pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger) component {
for (id key in self.urlLists) {
NSLog(@"key: %@, value: %@", key, [urlLists objectForKey:key]);
}
}
but I get the old EXC_BAD_ACCESS error...
I know Im missing something small, but what?
Thanks