Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding title to TableViewController

I am trying to figure out how to add a simple title to my swift project. I have listed students in a tableview and just want to add a title in the center above the list that says "STUDENTS" and I can't figure it out for the life of me. Every time I attempt to add anything it either is in the way of the carrier settings or does not appear. He is my code for everything but an attempted Title block.

class StudentRosterTableViewController: UITableViewController {

    var studentsList = [Dictionary<String, String>]()

    override func viewDidLoad() {
        super.viewDidLoad()

        let studentRoster = ClassRosterModel()
        studentsList = studentRoster.studentRoster
    }

// MARK: - Table view data source
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return studentsList.count
    }

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

        // Configure the cell...
        cell.textLabel!.text = studentsList[indexPath.row]["name"]
        cell.detailTextLabel!.text = studentsList[indexPath.row]["number"]

        return cell
    }
like image 854
Alex Kaczynski Avatar asked Oct 29 '25 00:10

Alex Kaczynski


1 Answers

If you are creating your UITableViewController without IB (Storyboard)

class StudentRosterTableViewController: UITableViewController {
    init() {
        super.init(style: .Plain)
        self.title = "StudentRoster"
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

With storyboard find View Controller section and type your title there.

enter image description here

like image 138
ale_stro Avatar answered Oct 31 '25 14:10

ale_stro