标签:
1.xib上的名为valueTextField的文本输入框的属性改为如下情形
2.插座变量
@property (weak, nonatomic) IBOutlet UITextField *valueTextField;
3.取消第一响应者
-(void)numberFieldCancle{ [self.valueTextField resignFirstResponder]; }
3.生成ToolBar
- (UIToolbar *)addToolbar { UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 50)]; // UIToolbar *toolbar =[[UIToolbar alloc] init]; UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(numberFieldCancle)]; toolbar.items = @[bar]; return toolbar; }
4.键盘升起时给键盘添加按钮
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { if (textField==self.valueTextField) { self.valueTextField.inputAccessoryView=[self addToolbar]; } return YES; }
5.注意哦,这个.m要遵守UITextFieldDelegate协议
@interface BNRItemDetailViewController ()<UITextFieldDelegate>
标签:
原文地址:http://www.cnblogs.com/Percy/p/5846717.html