简体   繁体   English

无法调用非函数类型'UITableView的值

[英]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)" 错误在线上:“返回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. 假设您在UITableViewController类中调用此方法。 Well, UITableViewController has a property called tableView . 好吧, UITableViewController有一个名为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. 因此,当您从super.tableView开始时,它会认为您正在请求该属性,这就是为什么它会给出tableView为非函数类型的错误的原因。

See if return super.tableView.rowHeight works for your case. 查看return super.tableView.rowHeight是否适合您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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