I’ve written the following code and for some reason the pickerView shows ????? instead of the array it should show.
The array has been defined in the header, and the dataSource has been set to the view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
arrayContext = [[NSMutableArray alloc] init];
[arrayContext addObject:@"is"];
[arrayContext addObject:@"wants"];
[arrayContext addObject:@"loves"];
[arrayContext addObject:@"hates"];
[arrayContext addObject:@"enjoyed"];
[arrayContext addObject:@"liked"];
[arrayContext addObject:@"likes"];
[pickerView selectRow:1 inComponent:0 animated:NO];
}
- (void)viewDidUnload
{
[textField release];
textField = nil;
[pickerView release];
pickerView = nil;
[arrayContext release];
arrayContext = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.ScotDev.QuickComPrefs.plist"];
NSString *chosenContext = [NSString stringWithFormat:@"%@ ", [arrayContext objectAtIndex:row]];
[plistDict setValue:chosenContext forKey:@"Context"];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [arrayContext count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [arrayContext objectAtIndex:row];
}
Is a
delegatemethod not adataSourcemethod. For your code to work both must be connected to this view controller.