3

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?

Rajat
  • 10,977
  • 3
  • 38
  • 55

1 Answers1

3

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.

Frankie
  • 11,508
  • 5
  • 53
  • 60
  • The error goes away and it runs. However, when I toggle between the date picker, the application immediately crashes and I get a "Thread 1: signal SIGABRT" error on this line in AppDelgate: class AppDelegate: UIResponder, UIApplicationDelegate { – Qusai Hussain Nov 19 '16 at 23:21
  • Something is probably nil; see http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu – Paulw11 Nov 19 '16 at 23:44
  • That may or may not be related to your original question or this solution. If my answer solved your original problem I'd appreciate if you accepted the answer. Then you should try to get detailed information about your new error and post another question and the community will try to help you out. – Frankie Nov 20 '16 at 00:25