ios - 单击单元格并转到其他视图控制器时应用程序崩溃
问题描述
我有一个带有表格视图和搜索栏的视图控制器。我想根据单元格中的文本将用户发送到其他三个视图控制器之一。
搜索视图控制器:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (searchBar.text == search[indexPath.row].cleanName) {
performSegue(withIdentifier: "songs", sender: self)
} else if (searchBar.text != search[indexPath.row].cleanName) {
performSegue(withIdentifier: "artist", sender: self)
} else {
performSegue(withIdentifier: "albums", sender: self)
}
}
每当我在第一个视图控制器中选择单元格时,我的应用程序崩溃并且我得到Thread 1: signal SIGABRT 'unable to dequeue a cell with identifier SearchTableViewCell - 必须为标识符注册一个 nib 或一个类,或者在情节提要中连接一个原型单元格'这个错误表明我必须为我的歌曲视图控制器注册一个 nib,但我已经这样做了。
SearhesViewController:
class SearchesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchesBar: UISearchBar!
var searchActive: Bool = false
var search = [Search]()
let filePath = "http://127.0.0.1/musicfiles"
var songs = [Songs]()
var artists = [Artist]()
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "SearchTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "SearchTableViewCell")
tableView.delegate = self
tableView.dataSource = self
searchesBar.delegate = self
retriveData()
print(search)
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
songs = songs.filter({ (songName) -> Bool in
return songName.songname.lowercased().range(of: searchText.lowercased()) != nil
})
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 120
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (searchActive) {
return search.count
} else {
return 1
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SearchTableViewCell", for: indexPath) as! SearchTableViewCell
cell.mainLabel!.text = search[indexPath.row].cleanName
cell.secondLabel!.text = songs[indexPath.row].artistId
cell.cellImage!.image = UIImage(named: songs[indexPath.row].cover)
return cell;
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let searchSong = search[indexPath.row].cleanName
let searchArtist = search[indexPath.row].artistid
let fileURLString = "\(filePath)\(searchSong)\(searchArtist)"
print(fileURLString)
}
解决方案
推荐阅读
- mongodb - 使用jhipster框架配置mongodb提示未授权
- python - UUID 到(十六进制数组?)
- javascript - 如果支持 Web 共享 API,它应该显示本机共享对话框,否则它应该转到锚标记的 href 中定义的 URL
- android - viewModel.setTitle(text) 是 android 中的反模式?
- javascript - 获取重复键错误,但未在集合中设置唯一属性
- date - 应用程序脚本上的区域时间和日期到谷歌表未转换为本地时间
- javascript - odataclient.query 不是 nodejs 中的函数
- python - 如何解决必须安装 CMake 才能构建以下扩展:PyCharm 中的 dlib?
- android - 我正在使用 kotlin 在 android 中使用芯片视图。我需要实现clickk功能
- python - 无法读取更大文件大小的镶木地板文件