The buttons should be visible when the user is done entering the value in the textfield

ε祈祈猫儿з 提交于 2020-01-05 07:25:24

问题


I have two textfields and two buttons and the button should not be visible till the user starts entering into the second textfield or the user has done entering in the second textfield. Thanks,


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

I did this but it doesn't work. Do I need to add this delegate method anywhere else?


回答1:


Set the UITextFieldDelegates, and tag the 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];
    }
}

Or something like that... You'll have to set the button to nil when the cursor is in the other textfield.

List of UITextFieldDelegates

Managing Editing

textFieldShouldBeginEditing:
textFieldDidBeginEditing:
textFieldShouldEndEditing:
textFieldDidEndEditing:

Editing the Text Field’s Text –

textField:shouldChangeCharactersInRange:replacementString:
textFieldShouldClear:
textFieldShouldReturn:



来源:https://stackoverflow.com/questions/5584833/the-buttons-should-be-visible-when-the-user-is-done-entering-the-value-in-the-te

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!