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

发布于 2024-10-14 08:20:17 字数 2272 浏览 6 评论 0原文

我遇到了一个小问题 -

(顺便说一句,我看过 如何呈现模式视图控制器选择联系人后? 但这对我没有帮助)

基本上我想让用户使用 - peoplePickerNavigationController 选择联系人。选择后我想呈现将使用 personRef 数据的ModalViewController。 我可以看到“添加人员”方法被调用,但 iPhone 不显示视图。

更新 - 如果我取消 DismissmissModalViewControllerAnimated 和 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];
}

非常感谢。

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 very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-10-21 08:20:17

只是不要忽略人员选择器并将您的控制器以模态方式显示在其之上。如果您随后在某个时候关闭控制器,则关闭人员选择器(来自调用者/父级),并且您的 ViewController 也将被关闭。

来自苹果文档:

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

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.

不再见 2024-10-21 08:20:17

虽然通过选择一个人,选择器会关闭,但关键是在选择一个人之后,在委托回调中自行关闭它,而不是呈现你的控制器

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

        }];

    }];

}

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

        }];

    }];

}
み青杉依旧 2024-10-21 08:20:17

我想你只需要等待人物选择器通过完成其动画而消失,它是通过调用 viewDidDisappear 来指示的。如果您覆盖并连接在那里,您应该保存以显示您的模态控制器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文