Note that there are some explanatory texts on larger screens.

plurals
  1. POTextField Keyboard doesnt dismisses
    primarykey
    data
    text
    <p>I am working with an app in xcode. Am stuck in a problem. I have made a table View and made a cell where i want to display 3 textFields and Labels. I have done it through coding and assigned textFields with tags. TextFields Keyboard is NumPad so for that i added a toolbar for dismissing the keyboard. toolbar have 2 buttons one cancel and one done. When i tap cancel button it dosent work for all textFields except the last textField. </p> <p>Kindly help me. </p> <p>Here is my code. </p> <pre><code> for (int i = 0; i &lt; 3; i++) { mainTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, (80 + (i * 60)), 280, 30)]; mainTextField.borderStyle = UITextBorderStyleRoundedRect; mainTextField.textColor = [UIColor blackColor]; mainTextField.font = [UIFont systemFontOfSize:17.0]; mainTextField.backgroundColor = [UIColor whiteColor]; mainTextField.autocorrectionType = UITextAutocorrectionTypeNo; mainTextField.backgroundColor = [UIColor clearColor]; mainTextField.keyboardType = UIKeyboardTypeNumberPad; mainTextField.keyboardType=UIKeyboardTypeDecimalPad; mainTextField.returnKeyType = UIReturnKeyDone; mainTextField.tag= i+1; mainTextField.delegate=self; [self.mainTableView addSubview:mainTextField]; self. numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; self. numberToolbar.barStyle = UIBarStyleBlackOpaque; self. numberToolbar.items = [NSArray arrayWithObjects: [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)], [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], nil]; [self.numberToolbar setTag:i+1]; [self.numberToolbar sizeToFit]; mainTextField.inputAccessoryView = numberToolbar; mainTextField.clearButtonMode = UITextFieldViewModeWhileEditing; mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 55+(i*60), 280, 18)]; mainLabel.backgroundColor = [UIColor clearColor]; mainLabel.textAlignment = UITextAlignmentLeft; mainLabel.tag= i+1; { mainLabel.text = [passedValue objectAtIndex:[mainLabel tag]-1]; [self.mainTableView addSubview:mainLabel]; [self configureView]; } } -(void)cancelNumberPad{ switch ([self.numberToolbar tag]) { case 1: [mainTextField resignFirstResponder]; break; case 2: [mainTextField resignFirstResponder]; break; case 3: [mainTextField resignFirstResponder]; break; default: break; } mainTextField.text = @""; } -(void)doneWithNumberPad { NSString *numberFromTheKeyboard = mainTextField.text; [mainTextField resignFirstResponder]; } </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.
 

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