更新2,我希望这对某人有帮助,在以下链接中有一个解决方案:https://discussions.apple.com/thread/5498630?start=0&tstart=0,显然这是一个iOS错误,这个工作正常。我可以创建新的sharedPicker,但我无法从中获取任何内容或忽略它,我不确定如何格式化超出链接提供的内容 任何有关这方面的帮助都是非常受欢迎的。
所以现在我的问题是如何采用以下代码并实际为peoplePickerNavigationControllerDidCancel创建代码:和peoplePickerNavigationController:shouldContinueAfterSelectingPerson: 谢谢。我已离开原始帖子的大部分,以防某人有类似的模糊问题。
// Convoluted workaround for the iPhone 4S crash
+ (ABPeoplePickerNavigationController *)sharedPeoplePicker {
static ABPeoplePickerNavigationController *_sharedPicker = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedPicker = [[ABPeoplePickerNavigationController alloc] init];
});
return _sharedPicker;
}
// then later on, use
[YourController sharedPeoplePicker].delegate = self;
// etc.
我目前的代码:
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self displayPerson:person];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
return NO;
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
//[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)pick1:(id)sender
{
ABPeoplePickerNavigationController *picker1 =[[ABPeoplePickerNavigationController alloc] init];
picker1.peoplePickerDelegate = self;
[self presentViewController:picker1 animated:YES completion:nil];
x=1;
}
更新1,此应用程序在iPhone 4 / 4s上崩溃,但在模拟器和iPhone5中运行,如果这意味着什么。我在想它只是有足够的力量来克服我创造的任何泄漏
我有一个带有视图控制器的iOS应用,用户可以使用ABPeoplePickerNavigationController
为应用选择联系人,也可以手动输入数字。如果手动输入数字则没有问题。如果用户打开并且:
从地址簿中选择一个新联系人
更新地址簿中的联系人以在应用中使用
打开并取消地址簿(所有内容均不保存操作)
然后我无法在没有崩溃的情况下导航到我的应用中的一个特定视图。我不知道为什么我不能去这个视图控制器,或者为什么它会导致崩溃。
我正在使用5个不同的选择器,每个联系人一个我想要添加并可能保存。我保存为NSUserDefaults
,但就像我说的那样,即使从未保存选择器选择,崩溃仍然存在。我可以通过侧边栏导航导航到应用程序中的所有视图而不会发生意外,我失败的视图唯一不同的是它是从一个主视图控制器而不是我的侧边栏呈现的。
我感谢任何帮助或想法。这是我写的第一个应用程序,我正在尝试更新它并失败。我想让它再次起作用,这样我就可以回来重构它了。
我的实施:
- (IBAction)pick1:(id)sender
{
ABPeoplePickerNavigationController *picker1 =
[[ABPeoplePickerNavigationController alloc] init];
picker1.peoplePickerDelegate = self;
[self presentViewController:picker1 animated:YES completion:nil];
x = 1;
}
- (IBAction)pick2:(id)sender
{
ABPeoplePickerNavigationController *picker2 =
[[ABPeoplePickerNavigationController alloc] init];
picker2.peoplePickerDelegate = self;
[self presentViewController:picker2 animated:YES completion:nil];
x=2;
}
- (IBAction)pick3:(id)sender
{
ABPeoplePickerNavigationController *picker3 =
[[ABPeoplePickerNavigationController alloc] init];
picker3.peoplePickerDelegate = self;
[self presentViewController:picker3 animated:YES completion:nil];
x=3;
}
- (IBAction)pick4:(id)sender
{
ABPeoplePickerNavigationController *picker4 =
[[ABPeoplePickerNavigationController alloc] init];
picker4.peoplePickerDelegate = self;
[self presentViewController:picker4 animated:YES completion:nil];
x=4;
}
- (IBAction)pick5:(id)sender
{
ABPeoplePickerNavigationController *picker5 =
[[ABPeoplePickerNavigationController alloc] init];
picker5.peoplePickerDelegate = self;
[self presentViewController:picker5 animated:YES completion:nil];
x=5;
}
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
[self displayPerson:person];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
return NO;
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
- (void)displayPerson:(ABRecordRef)person
{
NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person,
kABPersonFirstNameProperty);
NSString* phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,
kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phone = (__bridge_transfer NSString*)
ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else {
phone = @"[None]";
}
if (x==1){
firstName1.text = name;
contact1.text = phone;
}
if (x==2){
firstName2.text = name;
contact2.text = phone;
}
if (x==3){
firstName3.text = name;
contact3.text = phone;
}
if (x==4){
firstName4.text = name;
contact4.text = phone;
}
if (x==5){
firstName5.text = name;
contact5.text = phone;
}
}
答案 0 :(得分:3)
很抱歉回答我自己的问题,但另一个需要做些改动的工作就是使用CF Retain来纠正我遇到的过度释放。我保留了这个人和peoplePicker,所有人都得到了解决。感谢所有试图帮助我解决此问题的人。
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
CFRetain((__bridge CFTypeRef)(peoplePicker));
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self displayPerson:person];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
CFRetain(person);
CFRetain((__bridge CFTypeRef)(peoplePicker));
return NO;
}
答案 1 :(得分:1)
感谢您解决此问题。你的方法#2真的有效! 我在https://discussions.apple.com/thread/5498630?start=0&tstart=0中讨论过类似的情况:在故事板中由IB放置MKMapView,除了IBOutlet之外没有其他代码。我提出ABPeoplePickerController,然后通过dismiss取消它,并通过导航离开此视图。然后返回并获取内存问题:在被解雇的ABPeoplePickerController的地址处调用zombie UINavigationBar的方法barStyle。这种情况仅发生在iOS 7(iPad 3rd 10和iPhone 4S)上,但代码在iOS 6(iPhone 3GS)上运行良好,并且只与MKMapView结合使用。我使用WebView而不是MapView进行测试,一切正常。我认为这是iOS 7中的真正错误。 亲切的问候 阿列克谢
答案 2 :(得分:0)
嗯,还有一个更简单的解决方案。实际问题是使用ABPeoplePickerNavigationController
作为单个对象,将其委托设置为视图控制器,然后解除视图控制器。所以,就我而言,有效的解决方案就是这个:
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker
{
peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
[self displayPerson:person];
peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
return NO;
}