0

I am using swift and XCode 6.3.1. I edited a table view controller in storyboard with static cells. Wanting to program a label and a outlet, I created a new UITableViewController Cocoa Touch File and defined the view controllers class the Cocoa Touch File that I just made. However once I declared the class, nothing I edited in the storyboard appears in the simulator.

import UIKit

class TableViewController: UITableViewController {

    @IBOutlet weak var distanceSliderLbl: UILabel!
    @IBOutlet weak var distanceSlider: UISlider!


    override func viewDidLoad() {
        super.viewDidLoad()

        // 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()
    }

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

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 0
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return 0
    }


    @IBAction func distanceSlider_Slide(sender: AnyObject) {

        var currentValue = Int(distanceSlider.value)
        distanceSliderLbl.text = "\(currentValue)"

    }



    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell

        // Configure the cell...

        return cell
    }

Is there any way to fix this?

pengcheng95
  • 292
  • 4
  • 13

1 Answers1

0

Remove the three tableview functions that were generated by XCode when you created the file.

The first two functions dictate how many sections and rows your table will have. Right now you're saying your table has 0 sections, so that's exactly what you're getting- nothing. Since you have static cells you don't need the functions because the number is fixed by you in the storyboard. If you had dynamic cells that were generated by code, you may not know how many total sections and cells you'll have so you'd use those functions.

The third function would use the cell identifier to format your dynamically generated cells, but again, you don't need it because the cells are fixed (static)

Shades
  • 5,568
  • 7
  • 30
  • 48