Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We have a business rule where we need to restrict the editing of the email body content on MFMailComposeViewController. The content will be pre-populated and needs to remain static. Is it possible to grab the UITextView object and set it to disabled or something along those lines?

Another thought was to display a clear view over the top of the UITextView to prevent any interaction.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
692 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ok, so yes, the answer is that it is impossible without using private APIs.

I managed to do it with the following code.

- (void) getMFComposeBodyFieldViewFromView:(UIView *)view {
   for (UIView *item in view.subviews) {
    if ([[[item class] description] isEqualToString:@"MFComposeTextContentView"]) {
         self.mailBodyView = item;
         break;
      }
      if([item.subviews count] > 0) {
        [self getMFComposeBodyFieldViewFromView:item];
      }
   }
}

Then call the above method so that it sets the ivar mailBodyView and then call the _setEditable: method on UIWebDocumentView which MFComposeBodyField inherits from.

[self getMFComposeBodyFieldViewFromView:mailComposeViewController.view];
[self.mailBodyView setEditable:NO];

This causes the content in the body to be uneditable, the interaction is kind of funky because the keyboard still appears and you can still move the cursor around and select things but it definitely prevents the user from editing.

UPDATE

I updated the code to look for MFComposeTextContentView which is the parent of MFComposeBodyField and I call setEditable: on that object which prevents the keyboard from coming up, much better solution!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...