Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

Custom Cell Delegate Template

Wade Cantley

Generally, if I do a custom cell, I like to stick it in the same View Controller as the table it is going into.  So, here is a quick and dirty template with some comments to indicate where to group your methods.


//
//  ViewController.swift
//  TheFourLists
//
//  Created by Chris Cantley on 4/26/15.
//  Copyright (c) 2015 Chris Cantley. All rights reserved.
//

import UIKit

class DailyListViewController: UIViewController {

    //MARK: Variables
    let cellItem = DailyListItem()
   
    //MARK: Outlets
   
    //MARK: Actions
   
    //MARK: CV Delegates
   
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
}

//MARK: - Table Delegates & Functions
extension DailyListViewController: UITableViewDelegate {
   
    //MARK: Delegates
   
    func tableView(tableView: UITableView, 
                   numberOfRowsInSection section: Int) -> Int{
        return 1
       
    }
   
    // Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
    // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
   
    func tableView(tableView: UITableView, 
                   cellForRowAtIndexPath indexPath: NSIndexPath) 
      -> UITableViewCell{
       
        //NOTE : “cellItem” needs to be the identifier for the cell in the story board.
        let cell = tableView.dequeueReusableCellWithIdentifier("cellItem", forIndexPath: indexPath) as! DailyListItem
       
        cell.itemNameLabel.text = "Bob"
       
        return cell
       
    }
   
    //MARK: Custom Functions
   
}

//MARK: - DailyListItem Cell Class
class DailyListItem: UITableViewCell {
   
    //MARK: Variables
   
    //MARK: Outlets
   
    @IBOutlet weak var itemNameLabel: UILabel!
    //MARK: Actions
   
    //MARK: Delegates
   
    //MARK: Custom Functions
   
}