Coder Social home page Coder Social logo

mikewlange / uitableview-cache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kilograpp/uitableview-cache

0.0 1.0 0.0 21 KB

UITableView cell cache that cures scroll-lags on a cell instantiating

License: MIT License

Ruby 28.15% Objective-C 71.85%

uitableview-cache's Introduction

Build Status Pod Version codebeat badge Carthage compatible

UITableView + Cache

https://github.com/Kilograpp/UITableView-Cache

UITableView cell cache that cures scroll-lags on a cell instantiating.

Introduction

UITableView+Cache is a light UITableView category that purges scroll-lag that occurs on a new cell instantiation during scroll. It makes UITableView instantiate and cache cells before cellForRow:atIndexPath: call. It also provides simple interface very similar to existing registerClass/registerNib one.

Installation

CocoaPods

pod 'UITableView+Cache'

Carthage

github "Kilograpp/UITableView-Cache" "master"

Manual importing

Just add all files from src directory to your project.

Usage

When registering custom cells, call overriden registerClass/registerNib method instead of a default. UITableView+Cache swizzles dequeueReusableCellWithIdentifier methods with a private one that uses its own cache and implements registerClass/registerNib mechanism on itself. When dequeueReusableCellWithIdentifier is called and returns nil - the cache is asked for a cell. If cache is empty then cell is created using registered class or nib.

Swift

import UITableView_Cache

...

override func viewDidLoad() {
	super.viewDidLoad()

	self.tableView.registerClass(TableViewCodeCell.self, forCellReuseIdentifier: "MyReuseIdentifier", cacheSize: 10)
	self.tableView.registerNib(TableViewCodeCell.nib, forCellReuseIdentifier: "MyReuseIdentifier", cacheSize: 10)
}

...

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
	let cell = self.tableView.dequeueReusableCellWithIdentifier("MyReuseIdentifier") as! TableViewCodeCell
	return cell
}

Objective-C

- (void)viewDidLoad {
	[super viewDidLoad];

	[self.tableView registerClass:[TableViewCodeCell class] forCellReuseIdentifier:@"MyReuseIdentifier" cacheSize:10];
	[self.tableView registerNib:[TableViewNibCell nib] forCellReuseIdentifier:@"MyNibReuseIdentifier" cacheSize:10];
}

...

- (MyCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	MyCell* cell = [tableView dequeueReusableCellWithIdentifier:@"MyReuseIdentifier"];
	return cell;
}

Make sure to call dequeueReusableCellWithIdentifier:reuseIdentifier method and NOT dequeueReusableCellWithIdentifier:reuseIdentifier:forIndexPath: one. They perform different logic and a crash will occure on wrong method use.

License

UITableView+Cache is available under the MIT license. See the LICENSE file for more info.

Author

Mehdzor

uitableview-cache's People

Contributors

mehdzor avatar

Watchers

Mike Lange 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.