views:

365

answers:

0

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...
 }

Updated bonus information

It turns out that it works the first time that the cut/copy/paste popu is shown... not just the first time the UIAlertView is shown. So for example I can show and dismiss the alert view multiple times. And cut/copy/paste will still work the first time it's shown. But after that it will no longer work.

In addition... if I add a UITextField (not in an alert view) and show cut/copy/paste there then it won't ever show (even a first time) in the UITextField that's in the alert view. So in the end the problem seems to be that cut/copy/paste only shows in a UITextField in a UIAlertView if it's showing the edit popup for the first time in any UITextField.

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