我写了以下代码,由于某种原因,pickerView显示?????而不是它应该显示的数组。
数组已在标题中定义,dataSource已设置为视图控制器。
- (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];
}
答案 0 :(得分:1)
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
delegate
方法不是dataSource
方法。为了使您的代码工作,两者都必须连接到此视图控制器。