If you've been around the iOS world for a while, you've undoubtedly heard folks grumbling (or you've done some grumbling of your own) about the typical state of Apple's sample code. Don't get me wrong, there are occasionally absolute gems, like UIImage+ImageEffects (which has probably been added to half of the apps on the App Store today...), but it seems like these are few and far in between. One of the biggest omissions, in my opinion, has been the lack of sample code from Apple demonstrating how to properly manage data sources for your collection views and table views. Yeah yeah, I know what you're thinking, "what's there to know? I create a view controller with a table view, and then just set the datasource and delegate to self. Easy." And this is a fair thing to do for simpler cases, but when you start building up more complicated rules for populating your tables and collections, or when you want to reuse the view controllers, things can get hairy in a hurry.
Traditionally, to solve this sort of problem, I've always created a subclass of NSObject that implements UITableViewDataSource, and then created a new instance of the data source object, handed it to the table view, and continued on. And this works really well, but I've still suffered from a lack of best practices on which I can rely. Luckily, there was a session at WWDC this year that addressed just this issue, and provided some guidance around how Apple engineers have solved this problem in an app that Apple ships. And there's sample code, too!
Needless to say, this session, WWDC Session 232: Advanced User Interfaces with Collection Views, was one of the best I attended this year. Ole Begemann apparently agrees, and blogged about the talk at some more length. I highly recommend watching the session video and checking out the sample code. It's a great way to both promote code reuse and disentangle more complex relationships within your apps. Make sure you check it out!
Best,
Aaron
What We're Reading
- Design
- Dev
Control of the Week
DZNEmptyDataSet
Weekly Roundup
RACollectionViewReorderableTripletLayout
The custom collectionView layout that can perform reordering of cells by dragging it. pod 'RACollectionViewReorderableTripletLayout' MIT licensed. |
MZBookshelfCollectionViewLayout
Bookshelf like iBooks layout for UICollectionView. MIT licensed. |
GSIndeterminateProgressBar
iOS control that acts like indeterminate progress bar MIT licensed. |
LKAssetsLibrary
LKAssetsLibrary provides grouping / filtering / sorting functions for ALAssetsLibrary. MIT licensed. |
PI_EmojiPicker
Simple NSView or NSViewController based picker for Emoji. I took the wonderful work of AGEmojiKeyboard (https://github.com/ayushgoel/iOS-emoji-keyboard) as a base to create an OS X version. Its extremely simple and worth a couple hours of work. Its useful if you want to allow a user to enter Emoji without having to use the "special keyboard" in the edit menu. An example would be like Messages/iChat which has a smiley face picker next to the text entry. MIT licensed. |
Tattle-UI
btSimpleRippleButton
This is a custom button for iOS with a ripple effect. It is simple to integrate and is customizable. Supports a callback using blocks. MIT licensed. |
HRColorPicker
RColorPicker is a lightweight color picker for iOS that's easy to use for both users and developers. BSD licensed. |
AKTagsInputView
LMGeocoder
Simple wrapper for geocoding and reverse geocoding, using both Google Geocoding API and Apple iOS Geocoding Framework. MIT licensed. |
Glyphish Gallery
Browse and search through your Glyphish icons in style. Supports OS X 10.8+. License unspecified. |
VideoCover
A simple demo to add video in the background Apache 2.0 licensed. |
RSPOPPickerSheet
JPRequest
JPRequest is a simple Objective-C object to send and receive POST and GET data from a webservice MIT licensed. |
UAProgressView
UAProgressView is a simple and lightweight, yet powerful animated circular progress view. MIT licensed. |
Swift Spaceship Operator
INSSearchBar
An animating search bar. Originally developed for ShopNow v2. (http://www.shopnow.de) The search bar is designed as a standalone component that can be easily drag'n'dropped into any existing iOS project. For a story behind this control see http://salanki.com/insomniac/2014/06/03/the-search-bar-experiment/ License unspecified. |
BWTitlePagerView
Recreate the Twitter navigation controller pager. Apache 2.0 licensed. |
TMConsecutiveDayHelper
A pretty basic implementation to help keep track of a users streak of days where he/she has launched your app. The component uses NSUserDefaults to keep track of the dates. It also makes use of NSDate+Helpers category used in the PMCalendar repo here: https://github.com/kovpas/PMCalendar which is MIT Licensed. Install: Copy TMConsecutiveDayHelper.h and TMConsecutiveDayHelper.m into your project as well as NSDate+Helpers.h and NSDate+Helpers.m. Place a call to:
In your App Delegate's application didFinishLaunchingWithOptions: method Then to check on your users streak you can call: [TMConsecutiveDayHelper streakSizeInDays]; Or Alternatively call: [TMConsecutiveDayHelper hasComeBackForThisExactNumberOfDaysConsecutively:5] which returns a BOOL There's no logic as of yet to reset the streak but it could be added quite easily. basically you're responsible for what you want to do with the info and the class just keeps track of the streak itself. Downsides: Because the app uses NSUserDefaults it could be gamed pretty easily, by the user changing the date on their device. The component also uses ARC so if your project is using reference counting (ie retain release) then place the compiler flag ' -fobjc-arc ' inside the TMConsecutiveDayHelper.m row under the 'Compile Sources' located within the 'Build Phases' Tab for your App/Target settings. MIT licensed. |
ODSAccordionView
Yet another accordion style container view. MIT licensed. |
btSimplePopUp-Menu
BHTKeyboardAnimationBlocks
MNTPullToReact
MNTPullToReact is an extended evolution of the famous Pull to Refresh interaction. Apache 2.0 licensed. |
AFBlurSegue
Custom UIStoryboardSegue implementation for blurring the background of a modal view controller MIT licensed. |