0
如果此問題已在前面討論過,請原諒我。
我在UIPickerView中顯示數據有問題,只顯示問號「?」。
頭file.hUIPickerView無法正確顯示數據(僅顯示「?」)
#import <UIKit/UIKit.h>
@interface CustomPickerViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource> {
NSMutableArray *arrayColors;
}
@property (strong, nonatomic) IBOutlet UIPickerView *kotaPicker;
@end
impl.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.
}
你有沒有設置UIPickerView委託給文件所有者 – icodebuster 2013-05-04 17:20:10