Coder Social home page Coder Social logo

mytableviewmanager's Introduction

MYTableViewManager

Platform Language License Issues

I want to slim down my view controllers.

I want to manage tableview without the code of UITableViewDelegate and UITableViewDataSource.

That is why I created MYTableViewManager.

Feature

  • Don't have to write the code for UITableViewDelegate and UITableViewDataSource protocols
  • Don't have to set cell identifier
  • Handling cell selection by trailing closure
  • Easy to manage your cells (append/reset/insert/remove/update)
  • Easy to implement header/footer view
  • Support dynamic cell height from ios7
  • Support for creating cells from Nibs or Storyboards
  • Easy to implement loadmore
  • Complete example
Quick example
	// viewController class
	@IBOutlet weak var tableView: UITableView!
	private var tvManager: MYTableViewManager!

	override func viewDidLoad() {
		super.viewDidLoad()
		tnManager = MYTableViewManager(tableView: tableView)
		
		let title = "Cell Title"
		let cellData = MYTableViewCellData(cellClass: CustomCell.self, userData: title) {
			println("Did select cell with title = \(title)")
		}
		tvManager.appendData(cellData, inSection: 0, reloadType: .InsertRows(.Fade))
		//a cell of TextCell will be appended to tableView with Fade animation
	}       
	// your custom cell class
	class CustomCell : MYTableViewCell {
    @IBOutlet weak var titleLabel: UILabel!
    
    override func configureCell(data: MYTableViewCellData) {
        super.configureCell(data)
        if let title = data.userData as? String {
            titleLabel.text = title
        }
      }
	}

Usage

  • Initilization
	private var tvManager = MYTableViewManager(tableView: tableView)   
  • Register cell with simple syntax
	tvManager.registerCellClass(YourCellClassName)
	tvManager.regsiterCellNib(YourCellClassName)

	//of cource you don't need to register cell if your cell is included in the tableview storyboard

	// register header/footer view
	tvManager.registerHeaderFooterClass(MyHeaderClass)
	tvManager.registerHeaderFooterNib(MyHeaderClass)
  • Append a new cell with Fade animation
	let cellData = MYTableViewCellData(cellClass: CustomClass.self, userData: yourCellData) {
		println("Did select cell")
	}
	tvManager.appendDataInSection(0, data: cellData, reloadType: .InsertRows(.Fade))
  • Append a list of cells
	let items = [...] // or your data from API

	let cellData = items.map { item -> MYTableViewCellData in
		return MYTableViewCellData(cellClass: CustomCell.self, userData: item) {
			println("Did select cell")
		}
	}
	tvManager.appendData(cellData, inSection: 1, reloadType: .InsertRows(.None))
  • Reset section data
	// replace current data in section by new data
	tvManager.resetWithData([yourData], inSection: 0, reloadType: .ReloadSection(.Middle))

	// or reload all tableview
	tvManager.resetWithData(yourData, inSection: 0, reloadType: .ReloadTableView)

	// or without reload
	tvManager.resetWithData([yourData], inSection: 0, reloadType: nil)
  • Insert data
	tvManager.insertData(cellData, inSection: 0, atRow: 1)
	// insert a list of cellData
	tvManager.insertData([cellData1, cellData2], inSection: 0, atRow: 2)
	// setting insert animation
	tvManager.insertData([cellData1, cellData2], inSection: 0, atRow: 2, reloadType: .InsertRows(.Middle))

	tvManager.insertDataBeforeLastRow(cellData, inSection: 0, reloadType: .InsertRows(.Middle))
  • Remove data
	tvManager.removeDataInSection(0, row: 1)
	tvManager.removeData(cellData)
  • Update userData
	let newdata = tmp
	tvManager.updateUserData(newData, inSection: 0, atRow: 1, reloadCell: true)
  • set header/footer view
	let headerData = MYHeaderFooterViewData(viewClass: CustomHeaderView.self, userData: nil) {
		println("Did select header view")
	}
	tvManager.setHeaderData(headerData, inSection: 0)

	// you can enable/disable header in section
	tvManager.enableHeaderInSection(0)
	tvManager.disableFooterInSection(1)
  • loadmore
	tvManager.loadmore(delay: 0.2) {
		
	}
  • Reload type: MYTableViewManager supports some reload types as follows:

    • InsertRows(UITableViewRowAnimation)
    • DeleteRows(UITableViewRowAnimation)
    • ReloadRows(UITableViewRowAnimation)
    • ReloadSection
    • ReleadTableView
  • Handling cell

	// deselect the selected cell
	tvManager.deselectAllCells(animated: true)
  • Dynamic cell height : when you want to enable dynamic cell height, you only need to set the value of estimated height to the height parameter and set dynamicHeightEnabled = true
let cellData = MYTableViewCellData(cellClass: CustomClass.self, height: 50, userData: yourCellData) {
		println("Did select cell")
	}
	cellData.dynamicHeightEnabled = true
	
  • Cell callback
	func willAppear(data: MYTableViewCellData)
	func didDisappear(data: MYTableViewCellData)

TODO

  • prototyping
  • append/reset
  • insert
  • remove
  • update
  • header/footer
  • dynamic height for cells
  • dynamic height example
  • loadmore
  • create podfile

Installation

  • Installation with CocoaPods
	// coming soon
  • Copying all the files into your project
  • Using submodule

Requirements

  • iOS 7.0+
  • Xcode 6.1

License

MYTableViewManager is released under the MIT license. See LICENSE for details.

mytableviewmanager's People

Contributors

nghialv avatar

Watchers

James Cloos avatar Gaurav K avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.