Last active
August 29, 2015 14:09
-
-
Save iamjason/467047cb97672f425ae9 to your computer and use it in GitHub Desktop.
Swift TableView Data Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Jason Garrett on 10/21/14. | |
// Copyright (c) 2014 Jason Garrett. All rights reserved. | |
// | |
import UIKit | |
class TableViewDataManager : NSObject, UITableViewDataSource, UITableViewDelegate { | |
weak var vcDelegate:UIViewController! | |
var tableView:UITableView! | |
var data:NSArray = [AnyObject]() | |
func setUp(tableView:UITableView){ | |
self.tableView = tableView | |
//tableView.setTranslatesAutoresizingMaskIntoConstraints(false) | |
//tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0) | |
tableView.backgroundColor = UIColor.clearColor() | |
tableView.rowHeight = UITableViewAutomaticDimension; | |
tableView.estimatedRowHeight = 265.0; | |
tableView.dataSource = self | |
tableView.delegate = self | |
tableView.separatorStyle = .None | |
tableView.allowsSelection = false | |
tableView.showsVerticalScrollIndicator = false | |
} | |
func reloadData(){ | |
Async.main { | |
self.tableView.reloadData() | |
} | |
} | |
// MARK: - UITableViewDataSource | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return 1 | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 10 | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell") | |
cell.textLabel.text = "cell \(indexPath)" | |
return cell | |
} | |
// MARK: - UITableViewDelegate | |
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | |
println("Selected \(indexPath)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment