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:
精彩评论