我有一个带UISearchController的UITableView。当我没有搜索任何东西并选择一个单元格时,UIAlertController打开就好了,但是当我搜索一个单元格并选择它时,它会给我一个错误。
Warning: Attempt to present <UIAlertController: 0x15481000> on <Where.ViewController: 0x15344400> which is already presenting (null)
我不知道为什么会出现此错误/警告。
这是我的didSelectRowAtIndexPath和updateSearchResultsForSearchController委托:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if(self.resultSearchController.active)
{
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
print(currentCell.detailTextLabel!.text)
AlertMessage((currentCell.textLabel?.text)!, Number: (currentCell.detailTextLabel?.text!)!)
}
else
{
let indexPath = tableView.indexPathForSelectedRow!
let currentCell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
print(currentCell.detailTextLabel!.text)
AlertMessage((currentCell.textLabel?.text)!, Number: (currentCell.detailTextLabel?.text!)!)
}
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
PersonFilterArr.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF.name CONTAINS [c] %@", searchController.searchBar.text!)
let array = (self.PersonArr as NSArray).filteredArrayUsingPredicate(searchPredicate)
PersonFilterArr = array as! [Person]
self.ContactsTableView.reloadData()
}
这是我的UIAlerController,它应该在选择一个单元格时打开,但只有在你不搜索一个单元格时才能工作。希望你们能帮助你们。
func AlertMessage(Name: String, Number: String)
{
let alert = UIAlertController(title: "Send Message", message: "Tell " + Name + " where you are", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: { action in
print("Yes")
let messageVC = MFMessageComposeViewController()
messageVC.body = self.StreetName + " " + self.LocalityPostal + " " + self.AdministrativeArea + " " + self.Country;
messageVC.recipients = [Number]
messageVC.messageComposeDelegate = self;
self.presentViewController(messageVC, animated: true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.Default) { action in
print("No")
})
self.presentViewController(alert, animated: true, completion: nil)
}