所以我有一个弹出的选择器而不是键盘,但是当您滚动到选择器上的不同点时它不会改变值。我通过让警报显示选择了哪个年龄来测试这一点,并且它永远不会从第一个选项改变。我认为警报已损坏,但选择器中当前选定选项的蓝色选择器轮廓也没有显示。这是选择器和警报的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"18-29",@"30-39",@"40-49",@"50-59",@"60+",nil];
self.pickerData = array;
}
-(IBAction)UITextFieldEditingDidBegin
{
UIPickerView *picker = [[UIPickerView alloc]
initWithFrame:CGRectMake(0, 244, 320, 270)];
picker.delegate = self;
picker.dataSource = self;
[self.view addSubview:picker];
[picker release];
}
-(IBAction)donePressed
{
NSInteger row = [agePicker selectedRowInComponent:0];
NSString *selected = [pickerData objectAtIndex:row];
NSString *title = [[NSString alloc] initWithFormat:
@"You selected %@!", selected];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message : @"Thank you for choosing."
delegate:nil
cancelButtonTitle :@"Okay!"
otherButtonTitles :nil];
[alert show];
[agePicker resignFirstResponder];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [pickerData count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return[pickerData objectAtIndex:row];
}