我有两个文本字段和两个按钮,在用户开始进入第二个文本字段或用户已完成第二个文本字段输入之前,该按钮不可见。 谢谢,
- (void)textFieldDidBeginEditing:(UITextField *)secondFIB
{
if (secondFIB.tag == 1703) {
[self addPlusButton:[UIImage imageNamed:@"addButton1.png"] andFrameX:25 andFrameY:443 andFrameW:54 andFrameH:54];
[self addNextButton:[UIImage imageNamed:@"scenariosButton_active_green.png"] andTitle:@"Next." andFrameX:475 andFrameY:443 andFrameW:234 andFrameH:54];
/*UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];*/
}
}
我做了这个,但它不起作用。我是否需要在其他地方添加此委托方法?
答案 0 :(得分:1)
设置UITextFieldDelegates,并标记textFields(button.tag = someNumber;
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField.tag == someNumberOftheOneYouWant) {
// show Save Button
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}
}
或类似的东西......当光标在另一个文本字段中时,你必须将按钮设置为nil。
UITextFieldDelegates列表
管理编辑
textFieldShouldBeginEditing:
textFieldDidBeginEditing:
textFieldShouldEndEditing:
textFieldDidEndEditing:编辑文本字段的文本 -
文本字段:shouldChangeCharactersInRange:replacementString:
textFieldShouldClear:
textFieldShouldReturn: