Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextField in a UIActionSheet only calling some delegate methods
    primarykey
    data
    text
    <p>The below code shows that when a user does a long press gesture on a Table View Cell, then a <code>UIActionSheet</code> launches with a <code>UITextField</code> inside of it. When tapping the <code>UITextField</code>, the keyboard launches, and <code>textFieldShouldBeginEditing</code> and <code>textFieldDidBeginEditing</code> get called, but the text field won't accept the key taps.</p> <p>Hitting the return key won't trigger the delegate methods, but tapping one of the <code>UIActionSheet</code> buttons will trigger <code>textFieldShouldEndEditing</code> and then <code>textFieldDidEndEditing</code>.</p> <p>I'm setting the textField to become the first responder, so I'm not sure why it's not accepting input from the keyboard. Any suggestions?</p> <pre><code>- (void)longPress:(UILongPressGestureRecognizer *)gesture { // only when gesture was recognized, not when ended if (gesture.state == UIGestureRecognizerStateBegan) { // get affected cell SinTableViewCell *cell = (SinTableViewCell *)[gesture view]; // get indexPath of cell NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; // do something with this action NSLog(@"Long-pressed cell at row %d", indexPath); AppDelegate_Shared *appDelegate = (AppDelegate_Shared*)[UIApplication sharedApplication].delegate; //setup UITextField for the UIActionSheet UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 170, 320, 200)]; textField.borderStyle = UITextBorderStyleBezel; textField.backgroundColor = UIColorFromRGB(0XFFFFFF); textField.text = @""; textField.delegate = self; [textField setKeyboardType:UIKeyboardTypeAlphabet]; [textField setKeyboardAppearance:UIKeyboardAppearanceAlert]; //setup UIActionSheet UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Add Notes" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Save", nil]; [asheet showFromTabBar:appDelegate.tabBarController.tabBar]; [asheet setFrame:CGRectMake(0, 100, 320,380)]; [asheet insertSubview:textField atIndex:0]; //[textField becomeFirstResponder]; //memory management [textField release]; [asheet release]; } } #pragma mark - #pragma mark UIActionSheetDelegate - (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex { } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { } #pragma mark - #pragma mark UITextFieldDelegate - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { NSLog(@"textFieldShouldBeginEditing"); return YES; } - (void)textFieldDidBeginEditing:(UITextField *)textField { NSLog(@"textFieldDidBeginEditing"); [textField becomeFirstResponder]; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { NSLog(@"textFieldShouldEndEditing"); return YES; } //should save the notes value here, I think - (void)textFieldDidEndEditing:(UITextField *)textField { NSLog(@"textFieldDidEndEditing"); [textField resignFirstResponder]; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ return YES; } - (BOOL)textFieldShouldClear:(UITextField *)textField { NSLog(@"textFieldShouldClearEditing"); return YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSLog(@"in textFieldShouldReturn"); return YES; } </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