How do you focus on the TO field of MFMailComposeViewController?

I use the standard template code to send emails with the MFMailComposeViewController, but I canโ€™t find any information about setting focus on the TO field with the Plus button visible when the controller displays, like for features like the โ€œMail Link to this Pageโ€ in Safari or "Share Location" on Maps.

MFMailComposeViewController *mailComposer; mailComposer = [[MFMailComposeViewController alloc]init]; mailComposer.mailComposeDelegate = self; [mailComposer setSubject:@"My Subject"]; [mailComposer setMessageBody:@"This is the body of my message" isHTML:NO]; [self presentModalViewController:mailComposer animated:YES]; [mailComposer release]; 
+4
source share
1 answer

You can look inside the view of the mailComposer object:

 UIView *v0 = mailComposer.view; UIView *v1 = [[v0 subviews] objectAtIndex:0]; // UINavigationTransitionView UIView *v2 = [[v1 subviews] objectAtIndex:0]; // UIViewControllerWrapperView UIView *v3 = [[v2 subviews] objectAtIndex:0]; // MFMailComposeView UIView *v4 = [[v3 subviews] objectAtIndex:0]; // UIView UIView *v5 = [[v4 subviews] objectAtIndex:0]; // MFComposeScrollView UIView *v6 = [[v5 subviews] objectAtIndex:0]; // UIView UIView *v7 = [[v6 subviews] objectAtIndex:0]; // MFMailComposeRecipientView UIView *v8 = [[v7 subviews] objectAtIndex:1]; // _MFMailRecipientTextField 

This v8 guy is the one you want. This is a subclass of UITextField. Make him the first responder.

Officially, you should check the types of subitems instead of the first or second object. But then again, officially, you should not do this at all, as this is all undocumented and could be broken in future versions of iOS.

+2
source

All Articles