gpt4 book ai didi

ios - 与 Storyboard 连接的 SearchBar 为零

转载 作者:行者123 更新时间:2023-11-30 12:05:04 26 4
gpt4 key购买 nike

我使用的是 Xcode 9.0。

我的问题很简单:我在 TableViewController 中放置了一个 UISearchBar 对象。我将此 mySearchBar 作为 IBOutlet 连接到 TableViewController 类:

   class MyTableViewController: UITableViewController, UISearchBarDelegate, UINavigationControllerDelegate {

@IBOutlet weak var mySearchBar: UISearchBar!
@IBOutlet var myTableView: UITableView!
}
override func viewDidLoad() {
super.viewDidLoad()

navigationController?.delegate = self

self.mySearchBar.delegate = self // EXC_BREAKPOINT HERE
self.myTableView.delegate = self

self.myTableView.backgroundColor = UIColor.init(red: 0.0/255.0, green: 60.0/255.0, blue: 113.0/255.0, alpha: 1.0)
}

左侧的圆圈已填充 - 所以我确定该对象已正确连接。当我运行该项目时,它停在上面的行,并显示错误消息:

fatal error: unexpectedly found nil while unwrapping an Optional value.

我尝试过:

  • 清理项目并重建
  • 删除衍生数据,清理并重建
  • 删除 StoryBoard 中的 UIsearchBar 对象,删除一个新对象并作为 IBOutlet 重新连接
  • 销毁 StoryBoard 中的 Controller 并重新创建一个全新的 Controller 。

我不知道继续下去。任何帮助表示赞赏。我知道你可以!

编辑:这里是连接检查器的屏幕截图:enter image description here

EDIT2:Filtro Localita T 是我的 TableViewController,正如您在第二个屏幕截图中看到的 enter image description here

最佳答案

我解决了。问题出在插入这个 Controller 上。而不是:

let destinationView = FiltroLocalitaTableViewController()
destinationView.palina = self.transito.palina
self.navigationController?.pushViewController(destinationView, animated: true)

我用过:

let filtroLocalitaVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "filtroLocalitaView") as! FiltroLocalitaTableViewController
filtroLocalitaVC.palina = self.transito.palina
filtroLocalitaVC.delegate = self
self.navigationController?.pushViewController(filtroLocalitaVC, animated: true)

并且成功了。

关于ios - 与 Storyboard 连接的 SearchBar 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46772235/

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