简体   繁体   中英

Cannot call value of non-function type 'UITableView

I am trying to pop up date picker inside a static cell and I get this compiler error. Any thoughts?

The error is on line: "return super.tableView(tableView, heightForRowAtIndexPath: indexPath)"

import UIKit

class TableViewController: UITableViewController {

@IBOutlet weak var detailLabel: UILabel!
@IBOutlet weak var datePicker: UIDatePicker!
var datePickerHidden = false

override func viewDidLoad() {
    super.viewDidLoad()
    datePickerChanged()
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

@IBAction func datePickerValue(_ sender: UIDatePicker) {
    datePickerChanged()
}

func datePickerChanged () {
    detailLabel.text = DateFormatter.localizedString(from: datePicker.date, dateStyle: DateFormatter.Style.short, timeStyle: DateFormatter.Style.short)
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.section == 0 && indexPath.row == 0 {
        toggleDatepicker()
    }
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if datePickerHidden && indexPath.section == 0 && indexPath.row == 1 {
        return 0
    }
    else {
        return super.tableView(tableView: tableView, didSelectRowAtIndexPath: indexPath)
    }
}

func toggleDatepicker() {

    datePickerHidden = !datePickerHidden

    tableView.beginUpdates()
    tableView.endUpdates()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

How should I fix this issue?

Assuming that you're calling this inside a UITableViewController class. Well, UITableViewController has a property called tableView . So when you start off with super.tableView , it thinks you're asking for the property, which is why it gives the error that tableView is of non-function type.

See if return super.tableView.rowHeight works for your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM