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

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

iphone - Disable editing on MFMailComposeViewController

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

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

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...