• This repository has been archived on 06/Feb/2021
  • Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple UITableViewCell subclass with a scrollable content view, exposing an accessory view when scrolled. Inspired by the iOS 7 mail app. Supports iOS 5+

JGScrollableTableViewCell

Β© 2013-2014 Jonas Gessner


JGScrollableTableViewCell is a simple and easy to use UITableViewCell subclass with a scrollable content view that exposes an accessory view when scrolled. The behavior is inspired by the iOS 7 mail app.

Current Version: 1.1

Requirements

β€’ iOS 5 or higher
β€’ Built with ARC (If your Xcode project doesn't use ARC then set the -fobjc-arc compiler flag)
β€’ Foundation, UIKit and CoreGraphics frameworks

Getting started

JGScrollableTableViewCell works just like any other UITableViewCell: Highlighting, selection, and UITableViewDelegate calls all work like normal. The only difference is that the cell's contentView is covered by a UIScrollView that basically becomes the new content view – which is scrollable.

An "option view" can be assigned to the cell, which is placed behind the scroll view, making it possible to scroll on the cell to reveal the option view behind it.

Note: You should always use custom subclasses of JGScrollableTableViewCell that add your custom content to the cell (ex labels & image views).

Installation

CocoaPods:
Add this to your Podfile:

pod 'JGScrollableTableViewCell', '1.1'

Add source files:
Drag the JGScrollableTableViewCell folder into your project.

After you have included JGScrollableTableViewCell in your project, simply #import "JGScrollableTableViewCell.h" and you are ready to go!

Documentation

By default JGScrollableTableViewCell has an empty scroll area, and no option view. Here's a guide through the entire JGScrollableTableViewCell class:

####The scroll view

- (UIScrollView *)scrollView;

Returns the scroll view used in the cell. Do not add any subviews to the scrollview or modify its frame, bounds, contentOffset or contentInset.

- (void)setScrollViewInsets:(UIEdgeInsets)scrollViewInsets;

Insets the scroll view. Useful for displaying a border around the scroll area (when also setting contentView.backgroundColor)

- (void)setScrollViewBackgroundColor:(UIColor *)scrollViewBackgroundColor;

Sets the background color of the scroll view. Equivalent to contentView.backgroundColor on a regular UITableViewCell.

- (BOOL)isScrolling;

Returns YES if the user is currently dragging the scroll view or if the scroll view is decelerating.

- (void)setGrabberView:(UIView *)grabberView;

Sets a view to use as a grabber for the scroll view. This view is static, so it won't be resized at all by the cell. If this view is \c nil then the entire area of the scroll view is scrollable, if this view is set then scrolling can only be performed on this view.

####The option view

- (void)setOptionView:(UIView *)view ;

Sets a new option view & removes the old option view. The option view will be dynamically resized to fit the cell's size and the scroll view's insets. The only parameter of the option view's frame that is not changed is the width. The width should be set before passing the view to this method and should not be changed afterwards.

- (UIView *)optionView;

Returns the current option view.

- (void)setOptionViewVisible:(BOOL)optionViewVisible animated:(BOOL)animated;

Opens or closes the option view with an optional 0.3 second animation.

####Scrollable content

- (void)addContentView:(UIView *)view;

You should at no point add a view to the cell's directly or to its contentView. Instead, pass views that should be displayed on the cell to this method. Views passed to this method will appear in the scrollable area of the cell.

###Delegate JGScrollableTableViewCell has a delegate that conforms to the JGScrollableTableViewCellDelegate protocol. It is used for handling scroll events.

@property (nonatomic, weak) id <JGScrollableTableViewCellDelegate> scrollDelegate;


The JGScrollableTableViewCellDelegate protocol declares three optional (self explaining) methods:

- (void)cellDidBeginScrolling:(JGScrollableTableViewCell *)cell;
- (void)cellDidScroll:(JGScrollableTableViewCell *)cell;
- (void)cellDidEndScrolling:(JGScrollableTableViewCell *)cell;

Ideally, your UITableViewDelegate should also be your JGScrollableTableViewCellDelegate.

##Custom Touch handling

In some special cases custom touch handling may be needed (see Advanced example project). There are two blocks that can be used for customizing the scrolling behavior.

 @property (nonatomic, copy) void (^scrollViewDidScrollBlock)(JGScrollableTableViewCell *cell, UIScrollView *scrollView);

This block is invoked when the scroll view scrolls. Can be used to add custom behavior to the scroll view.

##Advanced usage

####Management of opened option views

JGScrollableTableViewCellManager
+ (void)closeAllCellsWithExceptionOf:(JGScrollableTableViewCell *)cell stopAfterFirst:(BOOL)stop;

This closes all option views in the table view that contains cell. stop is a flag that can increase performance by stopping the enumeration of cells after the first cell with an opened option view has been found and closed. Set this flag to YES when you have set up a JGScrollableTableViewCellDelegate to only allow one opened option view at a time (like in the following example).

Using this method call we can set up our table view to only allow one option view to be opened at at time:

- (void)cellDidBeginScrolling:(JGScrollableTableViewCell *)cell {
    [JGScrollableTableViewCellManager closeAllCellsWithExceptionOf:cell stopAfterFirst:YES];
}

- (void)cellDidScroll:(JGScrollableTableViewCell *)cell {
    [JGScrollableTableViewCellManager closeAllCellsWithExceptionOf:cell stopAfterFirst:YES];
}

- (void)cellDidEndScrolling:(JGScrollableTableViewCell *)cell {
    [JGScrollableTableViewCellManager closeAllCellsWithExceptionOf:cell stopAfterFirst:YES];
}

####Surviving UITableView's cell reuse Because UITableView reuses cells it is important to set the opened state of each cell when the UITableViewDataSource loads its data. To remember which cell was opened you can modify the cellDidEndScrolling: method to take note of the cell with the currently opened option view:

- (void)cellDidEndScrolling:(JGScrollableTableViewCell *)cell {
    if (cell.optionViewVisible) {
        _openedIndexPath = [self.tableView indexPathForCell:cell];
    }
    else {
        _openedIndexPath = nil;
    }

    [JGScrollableTableViewCellManager closeAllCellsWithExceptionOf:cell stopAfterFirst:YES];
}

(_openedIndexPath is an instance variable)

The tableView:cellForRowAtIndexPath: method should contain this code to update each cell's optionViewVisible state:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *const CellIdentifier = @"ScrollCell";
    
    JGScrollableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    [cell setOptionViewVisible:[_openedIndexPath isEqual:indexPath]]; //this correctly sets the opened state of the cell's option view.
    
    return cell;
}


Examples

There are two example projects located in the Examples folder.

Credits

Created by Jonas Gessner. Β©2013-2014

Contribution

You are welcome to contribute to the project by forking the repo, modifying the code and opening issues or pull requests.

License

Licensed under the MIT license.

More Repositories

1

JGProgressHUD

An elegant and simple progress HUD for iOS and tvOS, compatible with Swift and ObjC.
Objective-C
3,285
star
2

JGActionSheet

Feature-rich action sheet for iOS. This ActionSheet is a replacement for UIActionSheet, with iPad support!
Objective-C
855
star
3

JGDownloadAcceleration

Download acceleration for iOS. Based on NSURLConnection and NSOperation.
Objective-C
140
star
4

JGMethodSwizzler

Powerful and easy to use Objective-C swizzling API.
Objective-C
125
star
5

JGProgressHUD-SwiftUI

Easily show HUDs with SwiftUI! Lightweight SwiftUI wrapper for JGProgressHUD for iOS, tvOS, Catalyst.
Swift
99
star
6

JGProgressView

UIProgressView subclass with an animated "Indeterminate" setting (OS X Inspired)
Objective-C
52
star
7

ImageReducer

Drag & drop image reducer. Creates 2x and 1x images out of 3x images on the fly.
Objective-C
42
star
8

CCLoader

Developer utility for loading custom plugins into Control Center on iOS 7 and higher.
Objective-C
38
star
9

JGDetailScrubber

UISlider subclass with variable scrubbing speeds. Inspired by the iOS Music app.
Objective-C
35
star
10

Theos-NIC-Templates

Modern templates for NIC.
C
35
star
11

BrightnessFix

Restore Brightness after killing SpringBoard on iOS 6
Logos
8
star
12

Share-Widget-for-Control-Center

An example widget for Control Center. To be used with CCLoader
Objective-C
5
star
13

Theos-Install-Scripts

Useful scripts for theos projects to install packages via USB rather than SSH.
Python
5
star
14

Open-in-ProTube-2

Opens YouTube links directly in ProTube
Objective-C
4
star
15

SCION-WebRTC

Video Calls over SCION with advanced path control
Swift
4
star
16

SevenCenter

iOS 7 style NotificationCenter for iOS 5 & iOS 6
Logos
4
star
17

ETH-Algolab-2019

Solutions for the ETH Algorithms Lab problems for HS 2019
C++
3
star
18

BridgeConnect

Library for importing media using Bridge.
Objective-C
2
star
19

NoCarrier

Remove the carrier logo from the status bar on iOS.
C
2
star
20

Open-in-ProTube

Opens youtube URLs in ProTube app instead of YouTube app.
Objective-C
2
star
21

WebRTC

WebRTC builds for iOS and macOS that actually (hopefully) work...
C++
1
star
22

ascii85

macOS command line tool for ascii85 encoding and decoding
Swift
1
star
23

Flipswitch-Toggles

Additional switches for Flipswitch
C
1
star