Git Product home page Git Product logo

smart-tables's Introduction

SmartTables

Shows two simple techniques for modern UITableViews. The two techniques are separate in concept but are combined in this demo project, you can use either independently.

Computation of row height via auto-layout

The table view controller keeps a extra 'metrics' cell property that is used to populate and layout cells for height calculation purposes.

This is primarily useful for cells that use auto-layout. You no longer have to perform clumsy and awkward height calculation - just use auto-layout and you get height calculation for free.

The downside of this is that your cells are laid out twice and auto-layout is potentially expensive. You could mitigate this by caching the results of the first lay out and then reusing it for the second. But caching metrics is somewhat tricky to get right. The cache needs to be abandoned or updated if the table is editable or table size changes, rotations, dynamic text size changes (iOS 7) and probably under many other situations too.

In practice with the typical view you'd see in a table view (e.g. a complex tweet view) the double layout isn't expensive.

View controllers as cell prototypes

Use of UIViewControllers in table view cells and runtime generation of cell classes for specific view controllers

This is useful because table cells aren't usable outside of tables. By hosting content inside a view controller and then hosting that view controller inside a cell you can reuse that UI in other parts of your app very easily. This is often handy.

The technique generates at runtime a subclass of NTHostingTableViewCell that hosts a specific view controller class. This allows you to register a cell class with your table view as needed. This technique works very well with cell reuse.

Requirements

Project uses Xcode 5b3 (specifically the nibs) - but the techniques used work fine on iOS 6+.

smart-tables's People

Contributors

schwa avatar

Watchers

Kitsion 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.