gpt4 book ai didi

ios - 添加到 ABPersonViewController 的导航项在应用程序恢复时消失

转载 作者:行者123 更新时间:2023-11-29 11:20:41 24 4
gpt4 key购买 nike

我创建了一个 ABPersonViewController 并添加了一个完成按钮:

ABRecordRef rec = ABAddressBookGetPersonWithRecordID(addrBook, recordID);
if (rec) {
ABPersonViewController* personController = [[[ABPersonViewController alloc] init] autorelease];
personController.displayedPerson = rec;
personController.personViewDelegate = self;
personController.allowsEditing = NO;

UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target: self
action: @selector(dismissModalView:)] autorelease];

UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:personController] autorelease];
[self.appViewController presentModalViewController:navController animated: YES];

// this needs to be AFTER presentModal, if not it does not show up (iOS 4 regression: workaround)
personController.navigationItem.rightBarButtonItem = doneButton;

我应该怀疑它必须在呈现 View 后添加。

这一直有效,直到应用程序被发送到后台并激活此 View 。恢复应用程序后,完成按钮不再存在。我已经尝试了很多方法来添加这个完成按钮,但永远无法让它在应用暂停时保持不变。

最佳答案

这是解决方案。在 ABPersonViewController 前面创建一个空的 UIViewController。这将导致 ABPersonViewController 有一个后退按钮而不是创建的完成按钮。覆盖 ABPersonViewController(下面的 DisplayContactViewController)以便您可以实现 viewDidDisappear。这将在用户按下后退按钮时调用。在 viewDidDisappear 中,您可以取下整个导航堆栈(包括空的 View Controller )并返回到原始 View 。

    DisplayContactViewController* personController = [[[DisplayContactViewController alloc] init] autorelease];  // 
personController.displayedPerson = rec; // the ABPersonRecord to display
personController.personViewDelegate = self;
personController.allowsEditing = NO;
personController.contactsPlugin = self; //this is my hook so I can dismiss the picker view later

// create this so DisplayContactViewController will have a "back" button.
UIViewController* parentController = [[[UIViewController alloc] init] autorelease];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:parentController];

[navController pushViewController:personController animated:YES];

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

这里是 DisplayContactViewController viewDidDisappear。

[super viewDidDisappear: animated];
[self.contactsPlugin.appViewController dismissModalViewControllerAnimated:NO];

关于ios - 添加到 ABPersonViewController 的导航项在应用程序恢复时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7367528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com