在联系人列表(地址簿)上显示一个 AlertView

Presenting an AlertView on the contact list (AddressBook)

我正在从 AddressBookUI 中选择名字和姓氏。我正在控制用户名是否存在于我的数组中并且我可以找到它。

我的问题是我试图在用户点击 (select) 后显示和提醒视图,我遇到了这个问题,但我在下面遇到了这个问题,而我想在联系人列表。

Warning: Attempt to present on whose view is not in the window hierarchy!

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()

请问我的问题在哪里?

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController, didSelectPerson person: ABRecord) {

    let firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty)?.takeRetainedValue() as? String ?? ""
    let lastName  = ABRecordCopyValue(person, kABPersonLastNameProperty)?.takeRetainedValue() as? String ?? ""

    if let parentVC = self.parentViewController as? UIPageViewController{
        if let parentNewCarRequestVC = parentVC.parentViewController as? NewCarRequestViewController{

            let people:RequestPeople = RequestPeople()
            people.name = first
            people.surname = last

            if first.isEmpty || last.isEmpty{

               print("Error")

            }else{

                for item in parentNewCarRequestVC.request.peoples{

                    if item.name == firstName && item.surname! == lastName{

                        let alert:UIAlertController = UIAlertController(title: “Error”, message: “Same Number”, preferredStyle:.Alert)
                        viewController.presentViewController(alert, animated:true, completion:nil);

                        return
                    }
                }

                parentNewCarRequestVC.request.peoples.addObject(people)
            }

        }
        tableView.reloadData()
    }
}

如何将整个代码放入调度块中。

dispatch_async(dispatch_get_main_queue()) { () -> Void in
    let firstName ...
    ...
    if {...
    tableView.reloadData()
    }   
}