我在我的应用程序中实现了 ABPersonView 以允许查看联系人。选择电子邮件字段后,电子邮件应用程序将按预期打开,但灰色状态栏仅出现在 iPad 上,而在 iPhone 上则没有。我没有使用 IB,代码非常简单和标准来实现 ABPersonView。如果有人需要特定代码,请指定哪个代码部分。我很难过,因为这个问题只出现在 iPad 上。如何在 iPad 上停止这种行为?
编辑:我用一个虚拟项目重新创建了这种不受欢迎的行为。
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
@interface RootViewController: UIViewController <ABPersonViewControllerDelegate> {
}
@end
在.m
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.view.backgroundColor = [UIColor whiteColor];
self.view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(21, 80, 100, 35);
[myButton setTitle:@"My Button" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(myButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
}
-(void)myButtonPressed{
ABPersonViewController *personViewController = [[[ABPersonViewController alloc] init] autorelease];
personViewController.displayedPerson = [self personObject];
[self.navigationController pushViewController:personViewController animated:YES];
}
- (ABRecordRef)personObject {
ABRecordRef newRecord = ABPersonCreate();
ABRecordSetValue(newRecord, kABPersonFirstNameProperty, CFSTR("John"), nil);
ABRecordSetValue(newRecord, kABPersonLastNameProperty, CFSTR("Doe"), nil);
ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiPhone, @"1-222-333-4444", kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(newRecord, kABPersonPhoneProperty, multiPhone, nil);
CFRelease(multiPhone);
ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(multiEmail, @"123@abc.com", kABWorkLabel, NULL);
ABRecordSetValue(newRecord, kABPersonEmailProperty, multiEmail, nil);
CFRelease(multiEmail);
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:@"1234 AnyStreet" forKey:(NSString *)kABPersonAddressStreetKey];
[addressDict setObject:@"AnyTown" forKey:(NSString *)kABPersonAddressCityKey];
[addressDict setObject:@"AnyState" forKey:(NSString *)kABPersonAddressStateKey];
[addressDict setObject:@"55555" forKey:(NSString *)kABPersonAddressZIPKey];
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, nil);
ABRecordSetValue(newRecord, kABPersonAddressProperty, address, nil);
return newRecord;
}
- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
return YES;
}
@end