默认情况下是否可以在打开应用内电子邮件时将键盘对焦于“收件人”字段? 如果是,那么我们如何访问电子邮件中的“收件人”字段?
任何走向目标的道路都将受到赞赏。
答案 0 :(得分:2)
您可以使这些字段成为第一个响应者。
如果您将以下方法添加到您的班级......
//Returns true if the ToAddress field was found any of the sub views and made first responder
//passing in @"MFComposeSubjectView" as the value for field makes the subject become first responder
//passing in @"MFComposeTextContentView" as the value for field makes the body become first responder
//passing in @"MFRecipientTextField" as the value for field makes the to address field become first responder
- (BOOL) setMFMailFieldAsFirstResponder:(UIView*)view mfMailField:(NSString*)field{
for (UIView *subview in view.subviews) {
NSString *className = [NSString stringWithFormat:@"%@", [subview class]];
if ([className isEqualToString:field])
{
//Found the sub view we need to set as first responder
[subview becomeFirstResponder];
return YES;
}
if ([subview.subviews count] > 0) {
if ([self setMFMailFieldAsFirstResponder:subview mfMailField:field]){
//Field was found and made first responder in a subview
return YES;
}
}
}
//field not found in this view.
return NO;
}
然后,在您呈现MFMailComposeViewController之后,将MFMailComposeViewController的视图与您想成为第一响应者的字段一起传递给该函数。
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
/*Set up the mail composer*/
[self presentModalViewController:mailComposer animated:YES];
[self setMFMailFieldAsFirstResponder:mailComposer.view mfMailField:@"MFRecipientTextField"];
[mailComposer release];
编辑..
答案 1 :(得分:0)
以下代码可能对该问题有用
NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
NSLog(@"Defaults: %@", defaults);
如您所知,上面返回的默认值包含在字典对象中。字典中的键盘列表存储为NSArray对象。要检索数组,只需为对象“AppleKeyboards”
请求对象NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleKeyboards"];
NSLog(@"Keyboards: %@", array);