Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Section Names In Table Views

How can I take a text of textfield, and make it as name of a section in a tableview? I want to do this in Swift and Xcode 6. Thank you very much.

like image 253
Mert Karakus Avatar asked Oct 20 '25 02:10

Mert Karakus


2 Answers

You can use titleForHeaderInSection.

func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String!{
        if (section == 0){
            return textfield.text
        }
        if (section == 1){
            return textfield2.text
        }
    }
like image 115
Christian Avatar answered Oct 23 '25 01:10

Christian


SWIFT 3.0 come from @Christian 's answer.

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    if section == 0 {
        return ""
    } else {
        return ""
    }
}
like image 44
Jerome Avatar answered Oct 23 '25 02:10

Jerome



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!