当从另一个模态视图控制器调用时,ABPeoplePicker崩溃并且都被解雇 [英] Crash in ABPeoplePicker when called from another modal viewcontroller and both dismissed

查看:133
本文介绍了当从另一个模态视图控制器调用时,ABPeoplePicker崩溃并且都被解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(注意:我之前在项目的上下文中提交了这个问题,但我现在已经在测试项目中重新创建了崩溃。任何帮助告诉我我做错了什么都会受到赞赏。)

(Note: I filed this question before in the context of my project, but I've now recreated the crash in a test project. Any help in telling me what I'm doing wrong would be appreciated.)

从另一个模态viewcontroller调用ABPeoplePicker时发生崩溃。具体来说,主窗口有一个NavController,它加载myVC。 myVC然后加载一个包含我的控制器的模态NavController,然后调用ABPeoplePicker。在此演示程序中,在ABPeoplePicker运行之前不需要用户干预。

The crash occurs when calling ABPeoplePicker from another modal viewcontroller. Specifically, the main window has a NavController, which loads myVC. myVC then loads a modal NavController containing my controller, which then calls ABPeoplePicker. In this demo program, no user intervention is necessary until ABPeoplePicker runs.

如果您使用人员选择器中的搜索框,然后选择其中一个结果,则会发生崩溃人。 (如果你使用模拟器,你需要在运行程序之前在Contacts中添加一个人。)程序返回,但在解雇两个模态VC期间,我得到一个断言错误崩溃。它每次都出现在iphone,ipad和模拟器上。这似乎是很正常的事情,所以我发现很难相信这是一个真正的错误。崩溃消息是:

The crash occurs if you use the search box in the people picker, and then select one of the resulting people. (If you use the simulator, you'll need to add a person in Contacts before running the program.) The program returns, but during the dismissal of the two modal VCs, I get an assertion error crash. It occurs every time on iphone, ipad, and simulators for both. This seems a very normal thing to do, so I find it hard to believe this is a real bug. The crash message is:



中的断言失败 - [ABMembersSearchDisplayController setActive:animated:],
/ SourceCache / UIKit_Sim / UIKit-1448.69 / UISearchDisplayController.m:589 2011-01-31 13:51:11.903
testcrasher2 [26044:207] *
由于未被捕获而终止应用
exception
'NSInternalInconsistencyException',
原因:'搜索内容导航
控制器不得在
-setActive:YES和-setActive:NO'

Assertion failure in -[ABMembersSearchDisplayController setActive:animated:], /SourceCache/UIKit_Sim/UIKit-1448.69/UISearchDisplayController.m:589 2011-01-31 13:51:11.903 testcrasher2[26044:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'search contents navigation controller must not change between -setActive:YES and -setActive:NO'

为了演示,在新的Xcode iPhone Window应用程序中,我修改了didFinishLaunchingWithOptions来调用我的控制器。然后我按如下方式创建两个VC。 (注意你需要将Addressbook框架添加到目标。)这是整个程序......

So to demonstrate, in a new Xcode iPhone Window application, I modify the didFinishLaunchingWithOptions to call my controller. Then I create two VCs as follows. (Note you need to add Addressbook frameworks to the target.) Here's the entire program...

AppDelegate.didFinishLaunchingWithOptions:

AppDelegate.didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    myViewController *detailViewController = [[myViewController alloc] init];

    // Set the navigation controller as the window's root view controller and display.
    UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: detailViewController];

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];

    [detailViewController release];
    [navController release];

    return YES;
}

myViewController.h:

myViewController.h:

@interface myViewController :  UIViewController<addDelegate>{
 }
@end

myViewController.m:

myViewController.m:

#import "myViewController.h"
#import "AddNewViewController.h"        

@implementation myViewController

- (void)controllerDidFinish:(addNewViewController *)controller  {
    [self dismissModalViewControllerAnimated:YES];
}

-(void) viewWillAppear:(BOOL)animated  {
    [super viewWillAppear: animated];

    addNewViewController *addController = [[addNewViewController alloc] init];
    addController.delegate = self;

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addController];
    [self presentModalViewController:navController animated:YES];

    [navController release];
    [addController release];
}

@end

AddNewViewController.h:

AddNewViewController.h:

#import <AddressBookUI/AddressBookUI.h>

@protocol addDelegate;

@interface addNewViewController : UIViewController  < ABPeoplePickerNavigationControllerDelegate> {
    id <addDelegate> delegate;  
}
    @property(nonatomic, assign) id <addDelegate> delegate;
@end


@protocol addDelegate <NSObject> 
    - (void)controllerDidFinish:(addNewViewController *)controller ; 
@end

AddNewViewController.m:

AddNewViewController.m:

#import "AddNewViewController.h"

@implementation addNewViewController

@synthesize delegate;

-(void) viewDidAppear:(BOOL)animated {  
    ABPeoplePickerNavigationController * peoplepicker =  [[ABPeoplePickerNavigationController alloc] init] ;    
    peoplepicker.peoplePickerDelegate = self;
    [self presentModalViewController:peoplepicker animated:YES];
    [peoplepicker release];
}

#pragma mark AddressBook delegate methods

- (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { 
    [self dismissModalViewControllerAnimated:YES];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    [self.delegate controllerDidFinish:self ];  
    return NO;   //EDIT:  This MUST be YES or it will crash (see answer below)
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker 
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
      property:(ABPropertyID)property 
      identifier:(ABMultiValueIdentifier)identifier {
    return NO;
}

@end


推荐答案

原来这是一个实际的错误。确实如果你在用户点击搜索中的某个人时对你的ABPeoplePicker进行双重ModalVC解雇,你就会遇到这种崩溃。幸运的是,有一个简单的解决方法:在委托中输入YESContinueAfterSelectingPerson。当你同时解雇选择器时,无论你返回YES还是NO都没关系,它不会继续,但是NO会崩溃,YES则不会。 (与我的原帖相同: ABPeoplePicker中的奇怪崩溃

Turns out this is an actual bug. It is indeed true that if you do a double ModalVC dismiss to ABPeoplePicker when the user clicks a person in search, you'll get this crash. Fortunately, there's a simple workaround: return YES in your delegate's shouldContinueAfterSelectingPerson. As you're simultaneously dismissing the picker, it doesn't really matter whether you return YES or NO, it won't continue, but NO will crash and YES doesn't. (Same answer as for my original post: Weird crash in ABPeoplePicker )

这篇关于当从另一个模态视图控制器调用时,ABPeoplePicker崩溃并且都被解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆