首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >对成员'tableView(_:didSelectRowAt:)‘的引用不明确(Swift)

对成员'tableView(_:didSelectRowAt:)‘的引用不明确(Swift)
EN

Stack Overflow用户
提问于 2018-06-07 04:29:28
回答 1查看 1.3K关注 0票数 2

我正在尝试搜索一个显示在表视图中的数组,并且遵循了this教程,但是当我尝试调用reloadData()方法时,我得到了对成员'tableView(_:didSelectRowAt:)'的不明确引用

知道我错过了什么吗?

提前感谢你的建议。下面是我的ListController.swift代码:

import UIKit

var arrayIndex = 0

class ListController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate {


    let data = ["New York, NY", "Los Angeles, CA", "Chicago, IL", "Houston, TX",
                "Philadelphia, PA", "Phoenix, AZ", "San Diego, CA", "San Antonio, TX",
                "Dallas, TX", "Detroit, MI", "San Jose, CA", "Indianapolis, IN",
                "Jacksonville, FL", "San Francisco, CA", "Columbus, OH", "Austin, TX",
                "Memphis, TN", "Baltimore, MD", "Charlotte, ND", "Fort Worth, TX"]

    var filteredData: [String]!

    @IBOutlet var searchBarOutlet: UISearchBar!

    //Table Delegate
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        arrayIndex = indexPath.row
        performSegue(withIdentifier: "segue", sender: self)
    }

    // Table Data Source
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return filteredData.count
    }

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

        // Cell Data Source

        let cell = tableView.dequeueReusableCell(withIdentifier: "TableCell", for: indexPath) as UITableViewCell
        cell.textLabel?.text = filteredData[indexPath.row]


        // Cell Visual Formatting
        cell.backgroundColor = UIColor(red:0.05, green:0.05, blue:0.07, alpha:0)
        cell.textLabel?.textColor = UIColor.white
        cell.textLabel?.font = UIFont(name: "Raleway", size: 18)
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator

        return cell
    }

    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {

        filteredData = searchText.isEmpty ? data : data.filter { (item: String) -> Bool in
        return item.range(of: searchText, options: .caseInsensitive, range: nil, locale: nil) != nil
        }

        let tableView = UITableView()

        self.tableView.reloadData()
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "\(titles.count) Definitions"

        filteredData = data

}

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-07 04:39:49

您的tableView缺少@IBOutlet。因此,当您引用self.tableView时,Swift会认为您在谈论以tableView开头的方法之一。

所以,在searchBar(_:textDidChange:)中去掉这一行

let tableView = UITableView()

将插座添加到您的tableView并将其连接:

@IBOutlet weak var tableView: UITableView!
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50729070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档