点击UITextField弹出UIPickerView有一些不同的方法,特此标记一下本方法:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { UIPickerView *pickerView = [[UIPickerView alloc] init]; [pickerView sizeToFit]; pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); pickerView.delegate = self; pickerView.dataSource = self; pickerView.showsSelectionIndicator = YES; textField.inputView = pickerView; [pickerView release]; UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init]; keyboardDoneButtonView.barStyle = UIBarStyleBlack; keyboardDoneButtonView.translucent = YES; keyboardDoneButtonView.tintColor = nil; [keyboardDoneButtonView sizeToFit]; UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleBordered target:self action:@selector(pickerDoneClicked)] autorelease]; [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]]; textField.inputAccessoryView = keyboardDoneButtonView; [keyboardDoneButtonView release]; return YES; }
效果图: