1
static
dynamic
dynamic
dynamic
..
..
dynamic

I've a dynamic table list with dynamic content. At the top of list, I need a static cell.

And trying to add a Label in my static cell to try features.

My static cell's identifier is: firstCell

Dynamic cell's identifier is: cell

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

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


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

    // Configure the cell...

    cell.textLabel?.text = "test"


    return cell
}

This code return 5 times "test" in my dynamic cells. When I am try to add a Label and create outlet with static cell, get error.

I've googled and searched on stackoverflow but there is no swift version solution. How can do that?

EDIT FOR IMPROVE TO QUESTION:

Actually I need two section and section1 will be static content (I will create it programatically. E.g will use uidatepicker, uipicker and more..), section2 will work with just an dynamic array (this part is okey)

Mehmet
  • 3,301
  • 8
  • 26
  • 36
  • how do you mean _static_? do you want to add a section header or what exactly you are trying to achieve? – holex Jul 30 '15 at 07:59

3 Answers3

1

Have you tried something like this?

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

    if (indexPath.row == 1) {
        cell.textLabel?.text = "test"
    } else {
        // Configure the cell...
    }

    return cell
}
Kutyel
  • 8,575
  • 3
  • 30
  • 61
  • logically it worked, thanks but. How to configure my cell manual? For example I need a datepicker in one of my static cell. – Mehmet Jul 30 '15 at 07:59
  • 3
    That is another different question, check this [thread](http://stackoverflow.com/a/18973645/2834553). BTW, if you are going to mark my answer as correct, pls don't upvote it, just mark it as correct. Badge hungry ;P – Kutyel Jul 30 '15 at 08:02
1
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            var cell: IntroductionCell = self.tableView.dequeueReusableCellWithIdentifier("IntroCell") as! IntroductionCell
            cell.labelCellText.text = textArray[indexPath.row].uppercaseString
            return cell
        } else {
            var cell1: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("IntroCell1") as! UITableViewCell
            return cell1
        }
    }

Change the cell identifier for First Cell.

That's It LOL

Chetan Prajapati
  • 2,249
  • 19
  • 24
1

Override the functionality. Call super and change it up.

class TableViewController: UITableViewController {

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var rowCount = super.tableView(tableView, numberOfRowsInSection: section)
        if section == 1 {
            rowCount -= 1
        }
        return rowCount
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
        return cell
    }

}
  • the definition of override = "interrupt the action of; typically in order to take manual control" –  Feb 04 '17 at 10:13