对成员'tableView(_:numberOfRowsInSection :)的模糊引用

时间:2018-10-17 21:10:59

标签: ios swift tableview viewcontroller

想要将数据从具有TableView初始化的ViewController传递到另一个ViewController。但这向我显示了错误“对成员'tableView(_:numberOfRowsInSection :)的歧义引用”“

@IBOutlet weak var completedCaseTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    completedCaseTableView.delegate = self
    completedCaseTableView.dataSource = self

    // Do any additional setup after loading the view.
}


public func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return usrNameList.count
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CompletedCaseCell", for: indexPath) as! Admin_CompletedCases_TableViewCell

    cell.completedTktNum.text = usrTktList[indexPath.row]
    cell.completedUsrName.text = usrNameList[indexPath.row]

    cell.completedCustomerDp.image = UIImage(named: imageList[indexPath.row])

    cell.completedPostedDate.text = datesList[indexPath.row]
    cell.completedUsrReason.text = reasonList[indexPath.row]
    cell.statusOfCase.text = statusList[indexPath.row]



    return cell
}

public override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if (segue.identifier == "AdminCompletedDetailsSegue" ){

        let adminCompletedDvc = segue.destination as! Admin_Completed_Details_ViewController

        if let indexPath = self.tableView.indexPathForSelectedRow {

            adminCompletedDvc.newTktNumNew = usrTktList[indexPath.row] as String

            adminCompletedDvc.customerUsernameAdmnNew = usrNameList[indexPath.row] as String

            adminCompletedDvc.postedDateAdmnNew = datesList[indexPath.row] as String

            adminCompletedDvc.customerReasonAdmnNew = reasonList[indexPath.row] as String

            adminCompletedDvc.customerCommentsAdmnNew = commentList[indexPath.row] as String

            adminCompletedDvc.customerImgAdmnNew = imageList[indexPath.row] as String

        }

    }
}

Even after adding the tableview to tableview within Viewcontroller to Delegate and Datasource, and to @IBOUTLET, still getting this issue

1 个答案:

答案 0 :(得分:0)

问题在于,视图控制器中没有名为self.tableView的东西。名称为completedCaseTableView。所以改变这个:

if let indexPath = self.tableView.indexPathForSelectedRow {

对此:

if let indexPath = self.completedCaseTableView.indexPathForSelectedRow {