1

我有一个问题。ABUnknownPersonViewController 嵌入在顶部视图的导航控制器中,但是,我没有在我的应用程序中使用导航栏。推送到 ABUnknownPersonView 时,我没有看到导航栏或后退按钮。我的解决方案是这样的:

ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
unknownPersonViewController.unknownPersonViewDelegate = self;

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 41)]; navBar.delegate = self;

UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:@"Back"];
[navBar pushNavigationItem:backItem animated:NO];

UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:@"Your Title"];
[navBar pushNavigationItem:topItem animated:NO];
topItem.leftBarButtonItem = nil;

[unknownPersonViewController.view addSubview:navBar];
[self.navigationController pushViewController:unknownPersonViewController animated:YES];

所以这会添加一个导航栏,但后退按钮除了将标题更改为“后退”之外没有任何作用......非常有帮助,哈哈。此外,顶部的导航栏没有边界,所以我遇到了一些困难......下面的图片

以编程方式添加的导航栏

尝试返回时出现小问题...大声笑

4

1 回答 1

2

您可以尝试像这样以模态方式呈现它。我也没有在主视图中使用导航栏。这将在左上角添加一个取消按钮。

    ABUnknownPersonViewController *view = [[ABUnknownPersonViewController alloc] init];
    view.unknownPersonViewDelegate = self;

    //Add person record data

    view.displayedPerson = person;
    view.allowsAddingToAddressBook = YES;

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];

    view.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] 
       initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self 
       action:@selector(dismissContactView:)];

    [self presentViewController:nav animated:YES completion:nil];
于 2013-07-23T15:02:48.910 回答