簡體   English   中英

iOS 8:ABPeoplePickerNavigationController在實現人員選擇器委托方法時被解雇

[英]ios 8 : ABPeoplePickerNavigationController dismiss on implementing people picker delegate methods

這是從ios 8中的通訊錄訪問聯系人詳細信息時發現的奇怪行為。我的情況很簡單

  1. 顯示聯系人表
  2. 選擇將調用didSelectPerson方法的行
  3. 在didSelectPerson方法中
  4. 推送SecondViewController

     - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; { SecondViewController *detailVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [detailVC.view setBackgroundColor: [UIColor redColor]]; // [peoplePicker.navigationController pushViewController:detailVC animated:YES]; [peoplePicker pushViewController:detailVC animated:YES]; } 

但是發生的是ABPeoplePickerNavigationController關閉。 請對此給予啟發。

我不知道在“ didSelectPerson ”方法的幕后發生了什么,今天我也面臨着同樣的問題。 我找到了解決此問題的簡單解決方案,我重寫了“ ABPeoplePickerNavigationController ”的“ -(void)dismissViewControllerAnimated:(BOOL)flag補全:(void(^)(void))completion ”方法。 然后像下面這樣實現它

    bool dismissedEnabled;
   -(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
   {
     if (dismissedEnabled) {
       [super dismissViewControllerAnimated:flag completion:completion];
     }
   }

然后在“ didSelectPerson ”里面,我做了以下

   viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];

    dismissedEnabled = false;
    [self presentViewController:viewController animated:YES completion:nil];

這對我有用,希望你們也克服它:)

例如,如果您選擇一個電子郵件地址的聯系人,它將自動關閉。 如果聯系人有多個電子郵件,則必須指定一個謂詞,該謂詞將強制ABPeoplePickerNavigationController將ABPersonViewController推入堆棧。

if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
    {
        // The people picker will select a person that has exactly one email address and call peoplePickerNavigationController:didSelectPerson:,
        // otherwise the people picker will present an ABPersonViewController for the user to pick one of the email addresses.
        picker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"emailAddresses.@count = 1"];
    }

我相信iOS 8中的默認行為是,在調用didSelectPerson時,會自動關閉ABPeoplePickerNavigationController

未顯示SecondViewController的原因(我推斷這是問題症狀),是因為您正在嘗試在SecondViewController ABPeoplePickerNavigationController同時推動SecondViewController 這種重疊的動畫是iOS核心視圖管理/動畫系統試圖避免的問題。

發生這種情況時,您可能會在控制台中收到警告。

@Ratul的解決方案之所以有效,是因為它規避了這種默認行為。

在我的場景中,我的代碼在從didSelectPerson內部呈現UIAlertController之前睡了一秒鍾。 這是一個依賴於ABPeoplePickerNavigationController解雇動畫的過程,耗時不到一秒鍾。 對我而言,如果未顯示此警報,則沒人會注意到這是一個問題。

如果您想要更強大的功能,則可能需要重寫viewDidAppear來處理這種特殊情況(使用呈現的視圖控制器中的標志)。 但這也有些笨拙。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM