gpt4 book ai didi

ios - 在联系人列表 (AddressBook) 上呈现 AlertView

转载 作者:行者123 更新时间:2023-11-30 13:43:49 25 4
gpt4 key购买 nike

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

我的问题是,我试图在用户点击(选择)后呈现并提醒 View ,但我遇到了这个问题,但是当我想将其呈现在联系人列表上时,我在下面遇到了这个问题。

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()
}
}

最佳答案

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

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

关于ios - 在联系人列表 (AddressBook) 上呈现 AlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35219136/

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