【问题标题】:implementing search bar on tableview在 tableview 上实现搜索栏
【发布时间】:2017-12-26 11:11:50
【问题描述】:

我已经制作了单视图应用程序。我正在尝试在表格视图中实现搜索我的程序崩溃了

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     /*crashing  */ let cell = tableView.dequeueReusableCell(withIdentifier: "discoveryNewscell") as! DiscoveryNewsTableViewCell  //////crashing 
        cell.newsSneakerImage.image=sneakers[indexPath.row].image
        cell.newsTitle.text=sneakers[indexPath.row].news

        return cell


    } 

如何实现表格视图中的搜索栏搜索操作?您可以从此链接https://drive.google.com/file/d/1e4SuFbZLq7fOUeuJc59wYfIMvas3cJ-a/view?usp=sharing下载示例代码

【问题讨论】:

  • 在情节提要中重新检查您的 cellId,因为它是否与 discoveryNewscell 相同。
  • 是的,它们是一样的
  • 指定您的崩溃原因。
  • 无法将“UITableViewCell”(0x10d2e0778)类型的值转换为“DiscoveryNewsTableViewCell”
  • viewDidLoad()中删除self.DiscoveryNewsTableView.register(UITableViewCell.self, forCellReuseIdentifier: "discoveryNewscell")

标签: ios uitableview uisearchbar


【解决方案1】:

你在cellID中做错了,它与storyboard不同。

我将 cellID 从 cellForRowStoryboard 替换为 cellNew 并运行了您的项目,并且成功了。

检查输出或您的应用,

【讨论】:

  • 搜索不起作用。如何通过表格视图进行搜索
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多