点击UITextField弹出UIPickerView

点击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;
    
}

效果图:

效果图

posted on 2012-07-03 13:59  黯夜曦  阅读(2127)  评论(0编辑  收藏  举报

导航