如果这个问题之前已经讨论过,请原谅我。
我在 UIPickerView 中显示数据时遇到问题,它只显示问号“?” .
头文件.h
#import <UIKit/UIKit.h>
@interface CustomPickerViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource> {
NSMutableArray *arrayColors;
}
@property (strong, nonatomic) IBOutlet UIPickerView *kotaPicker;
@end
实现.m
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [arrayColors count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row {
return [arrayColors objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(@"The Data is %@", [arrayColors objectAtIndex:row]);
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrayColors = [[NSMutableArray alloc] init];
[arrayColors addObject:@"Red"];
[arrayColors addObject:@"Orange"];
[arrayColors addObject:@"Yellow"];
[arrayColors addObject:@"Green"];
[arrayColors addObject:@"Blue"];
[arrayColors addObject:@"Indigo"];
[arrayColors addObject:@"Violet"];
// Do any additional setup after loading the view from its nib.
}