开发者

presenting viewController after contact has been selected in peoplePickerNavigationController?

I am having a little problem -

(BTW i have looked on How can I present a modal view controller after selecting a contact? but it didnt help me)

Basically i want to let the user select a contact using the - peoplePickerNavigationController. after the selection i want to presentModalViewController that will use the personRef data. i can see that the "add person" method get called but the iphone does not present the view.

UPDATE - It works if i cancel the animation in the Dismiss dismissModalViewControllerAnimated and in the presentModalViewController, but then it looks pretty ugly.

this is the function called after the user selects the contact -

- (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;
}

this is the function called but still the view is not presenting -

- (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];
}

thank you ver开发者_如何学Pythony much.


Just don't dismiss the people picker and present your controller modally on top of it. If you afterwards dismiss your controller at some point dismiss the people picker instead (from the caller/parent) and your ViewController will be dismissed too.

From the Apple Docs:

dismissModalViewControllerAnimated: … If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack.


Although by picking a person, the picker dismisses, the key is to dismiss it yourself in the delegate callback, after picking a person and than present your controller

- (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:^{

        }];

    }];

}


I suppose you just have to wait until the people picker disappeared by finishing its animation which it indicates by calling viewDidDisappear. If you override and hook up in there, you should be save to present your modal controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜