Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think part of the problem is that you are handling the enabling/disabling of the bar buttons in a method that is only called once one of the bar buttons has been tapped. It would be better to set the barbuttonitems as properties of your view controller (so you can enable/disable them when you want to), and then handle the enabling/disabling of the bar button items within the UITextField's 'textFieldShouldBeginEditing' delegate method.</p> <p>So, something like this:</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { //UIToolBar for inputAccessoryView UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; self.moveToNextFieldButton = [[UIBarButtonItem alloc] initWithTitle:@"\U00003009" style:UIBarButtonItemStylePlain target:self action:@selector(nextTextField:)]; self.moveToPrevFieldButton = [[UIBarButtonItem alloc] initWithTitle:@"\U00003008" style:UIBarButtonItemStylePlain target:self action:@selector(prevTextField:)]; UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(backgroundTapped:)]; NSArray *toolBarButtons = @[self.moveToPrevFieldButton, self.moveToNextFieldButton, space, done]; toolBar.items = toolBarButtons; nameField.inputAccessoryView = toolBar; valueField.inputAccessoryView = toolBar; serialNumberField.inputAccessoryView = toolBar; } -(BOOL)textFieldShouldBeginEditing:(UITextField*)textField{ UITextField *next = textField.nextTextField; UITextField *prev = textField.prevTextField; self.moveToNextFieldButton.enabled = next != nil; self.moveToPrevFieldButton.enabled = prev != nil; return YES; } - (IBAction)nextTextField:(id)sender { UITextField *next = self.currentTextField.nextTextField; if (next) { [next becomeFirstResponder]; } } - (IBAction)prevTextField:(id)sender { UITextField *prev = self.currentTextField.prevTextField; if (prev) { [prev becomeFirstResponder]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload