I'm trying to add a UIPicker
to a UITextView
when it is selected to choose an age. 我找到了一个以前的线程并实现了代码,但我无法让它正常工作。当我构建程序时,选择器会出现,但其中没有值。关于我做错了什么的任何想法?另外,我在这里收到两个黄色错误,说“从不兼容的类型'ViewController *const __strong'分配给'id'”:
pickerView.delegate = self;
pickerView.dataSource = self;
谢谢你。
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *ageTextField;
@end
@implementation ViewController
@synthesize ageTextField;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIPickerView *pickerView =[[UIPickerView alloc]init];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator=YES;
ageTextField.inputView=pickerView;
}
- (void)pickerView:(UIPickerView *)PickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
NSMutableArray *ageArray = [[NSMutableArray alloc]init];
[ageArray addObject:@"1"];
[ageArray addObject:@"2"];
[ageArray addObject:@"3"];
[ageArray addObject:@"4"];
ageTextField.text=[ageArray objectAtIndex:row];
}