当用户完成在文本框输入值的按钮应该是可见的(The buttons should be visibl

2019-09-28 16:41发布

我有两个文本框和两个按钮,并直到用户开始进入第二个文本框或用户已经完成输入的文本框第二的按钮应该是不可见的。 谢谢,


- (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];*/
    }
}

我这样做,但它不工作。 我是否需要其他地方添加这个委托的方法?

Answer 1:

设置UITextFieldDelegates,并标记文本框(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:



文章来源: The buttons should be visible when the user is done entering the value in the textfield