Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 695
Qusai Hussain Avatar asked Dec 21 '25 20:12

Qusai Hussain


1 Answers

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.

like image 191
Frankie Avatar answered Dec 24 '25 10:12

Frankie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!