热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Swift-覆盖tableview函数-Method不会覆盖其超类中的任何方法

如何解决《Swift-覆盖tableview函数-Method不会覆盖其超类中的任何方法》经验,为你挑选了1个好方法。

我想实现UISearchController,使用本教程一步一步:

使用MKLocalSearchRequest搜索地点并使用UISearchController显示结果

在本节中......

使用MKLocalSearchRequest搜索位置

...我在步骤3中遇到问题.设置表视图数据源

extension LocationSearchTable {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return matchingItems.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
    let selectedItem = matchingItems[indexPath.row].placemark
    cell.textLabel?.text = selectedItem.name
    cell.detailTextLabel?.text = ""
    return cell
  }
}

错误:方法不会覆盖其超类中的任何方法

我正在尝试overridecellForRowAtindexPathtableView函数中删除,在这种情况下我在Xcode中没有错误,但执行后出错:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'UITableView (; layer = ; 
contentOffset: {0, -56}; contentSize: {375, 132};adjustedContentInset: {56, 0, 0, 0}>) 
failed to obtain a cell from its dataSource()'

错误消息大喊: failed to obtain a cell from its dataSource()

请告诉我,我做错了什么?我该如何处理这个问题?谢谢.



1> Puneet Sharm..:

本教程使用UITableviewDatasource方法的旧语法(可能是Swift 2.2):

你现在需要这些:

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

}

始终尽可能使用XCode的代码完成.


推荐阅读
author-avatar
finessi_739
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有