UITextField in UIAlertView doesn't respond to cut/copy/paste on second showing

Posted by Jesse Grosjean on Stack Overflow See other posts from Stack Overflow or by Jesse Grosjean
Published on 2010-03-11T20:20:53Z Indexed on 2010/03/11 20:24 UTC
Read the original article Hit count: 659

Filed under:
|
|

Edit Reposting... I accidentally marked my previous question as "commuity wiki" and didn't realize that answers to wiki posts don't generate reputation.

I"m adding a UITextView to a UIAlertView with the following code:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter Name Here" message:@"this gets covered!" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"OK!", nil]; UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)]; CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60); [alert setTransform:myTransform]; [myTextField setBackgroundColor:[UIColor whiteColor]]; [alert addSubview:myTextField]; [alert show]; [alert release]; [myTextField release];

If I place that code in a standard action method:

  • (IBAction)testAlertView:(id)sender { ...the above code... }

Then the first time I show the UIAlertView the cut/copy/paste popup menu will show in UITextField that's been added to the UIAlertView. (For instance if I tap and hold, then "Paste" will popup after I release.

The problem is after working correctly the first time, none of the cut/copy/paste buttons will show up again next time I show the UIAlertView (new instance) unless I restart the app. Does anyone know why, or how to fix this problem?

Bonus information

I just found out that I can get things to always work if I create an show the alert within a UIActionSheet delagate callback. For instance this always works (cut/copy/paste always shows up when in the UITextField when appropriate)

  • (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { ...the above code... }

Any idea what might be happening in this second case that make things work? I don't want to use a UIActionSheet in my app, so I'd like to find a way to make it work from a plain old action method.

Thanks, Jesse

© Stack Overflow or respective owner

UITextField in UIAlertView doesn't respond to cut/copy/paste on second showing

Posted by Jesse Grosjean on Stack Overflow See other posts from Stack Overflow or by Jesse Grosjean
Published on 2010-03-11T18:41:44Z Indexed on 2010/03/11 18:44 UTC
Read the original article Hit count: 659

I"m adding a UITextView to a UIAlertView with the following code:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter Name Here" message:@"this gets covered!" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"OK!", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12, 45, 260, 25)];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0, 60);
[alert setTransform:myTransform];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[alert show];
[alert release];
[myTextField release];

If I place that code in a standard action method:

- (IBAction)testAlertView:(id)sender {
    ...the above code...
}

Then the first time I show the alert view the cut/copy/paste popup menu will show in the text fields that's been added to the alert view. (For instance if I tap and hold, then "Paste" will popup after I release.

The problem is after working correctly the first time, none of the cut/copy/paste buttons will show up again when I show the alert view unless I restart the app. Does anyone know why, or how to fix this problem?

Bonus information

I just found out that I can get things to always work if I create an show the alert within a UIActionSheet delagate callback. For instance this always works (cut/copy/paste always shows up when in the UITextField when appropriate)

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    ...the above code...
}

Any idea what might be happening in this second case that make things work? I don't want to use a UIActionSheet in my app, so I'd like to find a way to make it work from a plain old action method.

Thanks, Jesse

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uialertview