3

我有一个小问题-

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

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

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

非常感谢您。

4

3 回答 3

3

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

来自苹果文档:

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

于 2011-02-03T18:51:43.487 回答
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:^{

        }];

    }];

}
于 2015-06-29T12:53:39.010 回答
0

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

于 2011-02-02T11:03:17.357 回答