Creating Custom TableView Cells in iOS

This entry is part 15 of 32 in the series iOS Apps

Creating Custom TableView Cells in iOS (Swift 2 : Xcode 7)


import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet var tableView: UITableView!
    var names = ["Mark", "Clyde", "Buck", "Steve", "Wallace"]
    var breeds = ["Labrador", "Bulldog", "German Sherpherd", "Golden Retriever", "Yorkshire"]
    var images = [UIImage(named: "Mark"), UIImage(named: "Clyde"), UIImage(named: "Buck"),UIImage(named: "Steve"), UIImage(named: "Wallace")]
    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.

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

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return names.count

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
        = images[indexPath.row] = names[indexPath.row]
        cell.breedName.text = breeds[indexPath.row]
        return cell


import UIKit

class CustomCell: UITableViewCell {

    @IBOutlet var photo: UIImageView!
    @IBOutlet var name: UILabel!
    @IBOutlet var breedName: UILabel!
    override func awakeFromNib() {
        // Initialization code

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
Series Navigation<< Swipe Navigation in Swift
Xcode 7 Swift 2 Tutorial – Random Number Generator >>

Leave a comment

Leave a Reply