在peoplePickerNavigationController中选择联系人后呈现viewController?

时间:2011-01-25 13:55:13

标签: iphone addressbook presentmodalviewcontroller

我有一点问题 -

(顺便说一句,我看过了 How can I present a modal view controller after selecting a contact? 但它没有帮助我)

基本上我想让用户使用--peoplePickerNavigationController选择一个联系人。在选择之后我想要使用personRef数据的presentModalViewController。 我可以看到“添加人”方法被调用,但iphone不显示视图。

UPDATE - 如果我在Dismiss dismissModalViewControllerAnimated和presentModalViewController中取消动画,它会起作用,但它看起来很难看。

这是用户选择联系人后调用的函数 -

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)personRef { 

    TempREcordId = ABRecordGetRecordID(personRef);

    BOOL hasDeleteDate = [GlobalFunctions CheckToSeeIfInHiBye:TempREcordId];

    if (hasDeleteDate) {
        [GlobalFunctions alert:NSLocalizedString(@"", @"") ];
    }else{

        [self addCustomValuesAfterSelection];
        [self dismissModalViewControllerAnimated:YES];
    }


    return NO;
}

这是被调用的函数,但视图仍未显示 -

- (void)addPerson {
    NSLog(@"@2");
    AddViewController *addViewController = [[AddViewController alloc] initWithStyle:UITableViewStyleGrouped];
    addViewController.delegate = self;

    // Create a new managed object context for the new book -- set its persistent store coordinator to the same as that from the fetched results controller's context.
    NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
    self.addingManagedObjectContext = addingContext;
    [addingContext release];

    [addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];


    addViewController.person = (Person *)[NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:addingContext];
    addViewController.hiByeGroupId = [dataSource hibyeGroupId];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addViewController];

    [self.navigationController presentModalViewController:navController animated:YES];

    [addViewController release];
    [navController release];
}
非常感谢你。

3 个答案:

答案 0 :(得分:3)

只是不要解雇人员选择器并以模态方式呈现控制器。如果您事后解雇您的控制器,则会解雇人员选择器(来自呼叫者/父母),您的ViewController也将被解雇。

来自Apple Docs:

  

dismissModalViewControllerAnimated:...   如果连续呈现多个模态视图控制器,从而构建一组模态视图控制器,则在堆栈中较低的视图控制器上调用此方法会解除其直接子视图控制器以及堆栈上该子视图上方的所有视图控制器。发生这种情况时,只有最顶层的视图以动画方式被删除;任何中间视图控制器都可以从堆栈中删除。

答案 1 :(得分:2)

虽然通过挑选一个人,挑选者解雇,但关键是在挑选一个人之后自己在代表回调中解雇它而不是呈现你的控制器

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person {

    [self.navigationController dismissViewControllerAnimated:YES completion:^{

        ContactDetailViewController * vc = [[ContactDetailViewController alloc] initWithWithABRecord:person];
        vc.delegate = self;
        UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
        [self.navigationController presentViewController:nc animated:YES completion:^{

        }];

    }];

}

答案 2 :(得分:0)

我想你只需要等到人们选择器消失后,通过调用viewDidDisappear来表示动画。如果你在那里覆盖并挂钩,你应该保存以显示你的模态控制器。