UIAlertView 中的 UITextField 在第二次显示时不响应剪切/复制/粘贴

发布于 2024-08-25 08:11:32 字数 1708 浏览 2 评论 0原文

编辑重新发布...我不小心将我之前的问题标记为“社区维基”,并且没有意识到维基帖子的答案不会产生声誉。

我使用以下代码将 UITextView 添加到 UIAlertView:

 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];

如果我将该代码放在标准操作方法中:

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

那么第一次显示 UIAlertView 时,剪切/复制/粘贴弹出菜单将显示在已添加到的 UITextField 中UIAlertView。(例如,如果我点击并按住,则在释放后会弹出“粘贴”。

问题是第一次正常工作后,下次显示 UIAlertView 时不会再次显示剪切/复制/粘贴按钮(新实例)除非我重新启动应用程序,有谁知道为什么,或者如何解决这个问题?

奖励信息

我刚刚发现,如果我创建一个显示警报,我可以让事情始终正常工作。例如,在 UIActionSheet 延迟回调中,这总是有效(剪切/复制/粘贴总是在适当的时候在 UITextField 中显示)

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

更新的奖金信息

事实证明,它在第一次剪切/时有效。显示复制/粘贴 popu...不仅仅是第一次显示 UIAlertView 时。例如,我可以多次显示和关闭警报视图。剪切/复制/粘贴在第一次显示时仍然有效。但此后它将不再起作用。

另外...如果我添加一个 UITextField (不在警报视图中)并在那里显示剪切/复制/粘贴,那么它永远不会在警报视图中的 UITextField 中显示(即使是第一次)。因此,最终问题似乎是,如果第一次在任何 UITextField 中显示编辑弹出窗口,则剪切/复制/粘贴仅显示在 UIAlertView 中的 UITextField 中。

你知道在第二种情况下会发生什么事情才能让事情顺利进行吗?我不想在我的应用程序中使用 UIActionSheet,所以我想找到一种方法让它从普通的旧操作方法开始工作。

谢谢, 杰西

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2024-09-01 08:11:32

老实说,我认为这个想法违反了 UI 指南……这将构成应用程序商店的拒绝,除非你有充分的理由。

这是苹果定义的使用 UIAlertView

http://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW8老实说

,我认为您只是想切换到另一个视图...

抱歉,我无法提供更多帮助。

To be honest I think this idea violates the UI Guidelines... Which would constitute a rejection for the app store unless you have a good reason.

This is Apples defined use UIAlertView

http://developer.apple.com/library/ios/documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW8

Honestly I'd think you'd just want to switch to an alternate view...

Sorry I can't be of more help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文