开发者

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

开发者 https://www.devze.com 2023-02-23 00:46 出处:网络
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.

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:@"scenarios开发者_如何学JAVAButton_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?


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:

0

精彩评论

暂无评论...
验证码 换一张
取 消