gpt4 book ai didi

swift - 与协议(protocol) 'UISearchBarDelegate' 的冗余一致性 - Swift 4

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

我有这个错误

Redundant conformance of 'TodoListViewController' to protocol 'UISearchBarDelegate'

第 1 行的“UISearchBarDelegate”上弹出错误。

extension TodoListViewController: UISearchBarDelegate {

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

let request : NSFetchRequest<Item> = Item.fetchRequest()

let predicate = NSPredicate(format: "title CONTAINS[cd] %@", searchBar.text!)

request.predicate = predicate

let sortDescriptor = NSSortDescriptor(key: "title", ascending: true)

request.sortDescriptors = [sortDescriptor]

do {
itemArray = try context.fetch(request)
} catch {
print("Error fetching data from context \(error)")
}

tableView.reloadData()

}
}

TodoListViewController 的类声明:

class TodoListViewController: UITableViewController, UISearchBarDelegate {

我已经对此进行了研究,并且没有其他问题对我的错误有效。

最佳答案

您在扩展名 extension TodoListViewController: UISearchBarDelegate {

处添加委托(delegate)

在声明时类 TodoListViewController:UITableViewController,UISearchBarDelegate {

将其从声明中删除

class TodoListViewController: UITableViewController {

}

关于swift - <viewcontroller> 与协议(protocol) 'UISearchBarDelegate' 的冗余一致性 - Swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50773465/

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