cavuco
cavuco

Reputation: 99

MFMailComposeViewController iphone keyboard does not have DONE or CANCEL

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.

Upvotes: 0

Views: 1238

Answers (2)

jrturton
jrturton

Reputation: 119272

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.

Upvotes: 1

Luke Fletcher
Luke Fletcher

Reputation: 348

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

Upvotes: 0

Related Questions