MFMailComposeViewController iphone 键盘没有 DONE 或 CANCEL

发布于 2024-12-22 03:06:00 字数 119 浏览 0 评论 0原文

MFMailComposeViewController 附带的键盘一旦出现就没有任何方法可以关闭键盘。 有谁有换键盘的想法吗?由于您当时实际上在邮件客户端中,所以没有暴露 UITextField

The keyboard that comes up with MFMailComposeViewController does not have any means to dismiss the keyboard once it comes up.
Does anyone have an idea of changing the keyboard. There are no UITextField exposed as you are actually in mail client at the time.

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

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

发布评论

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

评论(2

黎夕旧梦 2024-12-29 03:06:00

邮件编辑器不是您可以修改的,它是系统提供的视图控制器,在文档中明确告诉您不要修改:

重要提示:邮件撰写界面本身不可自定义,并且您的应用程序不得对其进行修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改将被忽略。因此,您必须在呈现界面之前设置内容字段的值。

左上角已经有取消按钮,“完成”会做什么?发送电子邮件?那是在右上角。

The mail composer isn't yours to modify, it is a system provided view controller which you are explicitly told not to modify in the docs:

Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.

The cancel button is already there in the top left, what would "Done" do? Send the email? That's in the top right.

梦归所梦 2024-12-29 03:06:00

MFMailComposeViewController 没有“完成”按钮,因为它假设您将使用该按钮作为返回键(以创建新行)。

如果您确实想将按钮更改为“完成”按钮,我只能想到一种方法:

  1. 创建一个新的 MFMailComposeViewController。
  2. 通过[[mailComposer view]子视图]进行枚举。
  3. 检查每个子视图(以及子视图的子视图,如果需要)。
  4. 当您找到作为正文的 UITextView 时,请执行以下操作:

    // 从子视图检查中获取UITextView
    UITextView *textView;
    
    // 在你的类中声明这个实例变量 @interface
    id ;原始的TextViewDelegate;
    
    // 获取原始委托
    原始TextViewDelegate = [textView委托];
    
    // 重写委托
    [textView setDelegate:self];
    
    // 设置返回键类型
    [textView setReturnKeyType:UIReturnKeyDone];
    
  5. 在 -textViewShouldEndEditing 上返回 YES。实现所有 UITextViewDelegate 方法,并调用originalTextViewDelegate(有点像在子类上调用“super”)。

    - (BOOL)textViewShouldEndEditing:(UITextView *)textView
    {
        [originalTextViewDelegate textViewShouldEndEditing:textView];
        // 重要提示:无论 OriginalTextViewDelegate 的响应如何,都返回 YES 
        返回是;
    }
    
    - (void)textViewDidChangeSelection:(UITextView *)textView
    {
        [originalTextViewDelegate textViewDidChangeSelection:textView];
    }
    
    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)范围 replacementText:(NSString *)text
    {
        返回 [originalTextViewDelegate textView:textView shouldChangeTextInRange:范围 replacementText:text];
    }
    
    // ETC
    

这应该可行,但不能保证。希望有帮助! :D

The MFMailComposeViewController doesn't have a "Done" button, because it assumes you will use that button as a return key (to make a new line).

If you really wanted to change the button to a "done" button, there is only one way I can think to do it:

  1. Create a new MFMailComposeViewController.
  2. Enumerate through [[mailComposer view] subviews].
  3. Inspect each subview (and subviews of subviews, if required).
  4. When you've found the UITextView that is the body, do the following:

    // Get the UITextView from subview inspection
    UITextView *textView;
    
    // Declare this instance variable in your class @interface
    id <UITextViewDelegate> originalTextViewDelegate;
    
    // Get the original delegate
    originalTextViewDelegate = [textView delegate];
    
    // Override the delegate
    [textView setDelegate:self];
    
    // Set the return key type
    [textView setReturnKeyType:UIReturnKeyDone];
    
  5. Return YES on -textViewShouldEndEditing. Implement ALL UITextViewDelegate methods, and call originalTextViewDelegate (kind of like calling "super" on a subclass).

    - (BOOL)textViewShouldEndEditing:(UITextView *)textView
    {
        [originalTextViewDelegate textViewShouldEndEditing:textView];
        // Important: return YES, regardless of originalTextViewDelegate's response 
        return YES;
    }
    
    - (void)textViewDidChangeSelection:(UITextView *)textView
    {
        [originalTextViewDelegate textViewDidChangeSelection:textView];
    }
    
    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        return [originalTextViewDelegate textView:textView shouldChangeTextInRange:range replacementText:text];
    }
    
    // etc
    

That should work, but no guarantees. Hope that helps! :D

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