Giter VIP home page Giter VIP logo

bmxswipablecell's Introduction

BMXSwipableCell

A custom UITableViewCell that supports cell dragging gesture to reveal a custom menu of buttons or other views. It supports:

  • fully customizable UIView to use as a canvas for custom buttons and views;
  • Auto Layout;
  • storyboards;
  • easy cell reuse;
  • highlight / unhighlight of cells;
  • selection / deselection of cells;
  • normal and edit mode;
  • accessory views;
  • compatible with iOS 7 and 8.

BMXSwipableCell try to mimic the original behaviour of iOS7 Mail App by all aspects.

image

BMXSwipableCell is storyboard-friendly as does not implements cell contents on its own but uses the elements defined in Interface Builder. It is of course possible to implement the content by code.

image

BMXSwipableCell is generic in terms of what to show when a cell is swiped. It could be two buttons, one buttons or an entirely different content. For this reason BMXSwipableCell does not implement "More" and "Delete" buttons on its own, but it exports a basement view, that is the view underneath the original content view defined in Interface Builder. In tableView:cellForRowAtIndexPath it is then possible to add the desidered buttons or view.

Installation

From CocoaPods

Add pod 'BMXSwipableCell' to your Podfile.

Manually

Drag BMXSwipableCellDemo/BMXSwipableCell folder into your project and add it to your targets.

Usage

  1. If you're using Interface Builder, define the Custom Class of the cell as BMXSwipableCell. If you're going by code, register BMXSwipableCell with your UITableView.
  2. Implement the tableView:cellForRowAtIndexPath method and configure the cell as desired. Here it is done by a category:
- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    
	BMXSwipableCell *cell = (BMXSwipableCell *)
	    [tableView dequeueReusableCellWithIdentifier: @"Cell"
	                                    forIndexPath: indexPath];
    
	[cell configureCellForItem: [_data objectAtIndex: indexPath.row]];

	return cell;
} 

Before adding subviews to the basement you can check if the cell was already initialized using the property basementConfigured (cell that get reused can already have the custom basement content):

@implementation BMXSwipableCell (ConfigureCell)

- (void)configureCellForItem:(BMXDataItem*)item
{
    CGFloat cellHeight = CGRectGetHeight(self.bounds);
    CGFloat x = self.basementVisibleWidth - cellHeight * 2;
    
    //
    // configure cell only if not already done
    //
    if (!self.basementConfigured) {    
	    // first button...
    
    	//
    	// delete button
    	//
	    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
	    deleteButton.backgroundColor = 
	    	[UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0f];
	    deleteButton.frame = CGRectMake(x + cellHeight, 0, cellHeight, cellHeight);
	    [deleteButton setTitle:@"Delete" forState:UIControlStateNormal];
	    [deleteButton setTitleColor:[UIColor whiteColor] 
	    					forState: UIControlStateNormal];
	    [deleteButton addTarget: self
	                     action: @selector(userPressedDeleteButton:)
	           forControlEvents: UIControlEventTouchUpInside];
	    
	    [self.basementView addSubview: deleteButton];
    }
    
    // configure cell contents

}
//... more
  1. Add few methods to your UITableViewController / UITableViewDelegate to manage automatic hiding of basements when device is rotated or when the list is scrolled:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                duration:(NSTimeInterval)duration 
{
    
    [super willRotateToInterfaceOrientation: toInterfaceOrientation
                                   duration: duration];
    
    [BMXSwipableCell coverBasementOfAllCells];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [BMXSwipableCell coverBasementOfAllCells];
}

This code is also available in the UITableViewController+BMXSwipableCellSupport category for your convenience.

Check out the sample project for a complete usage example.

Notes about Interface Builder

  1. Remember to set Custom Class to BMXSwipableCell.
  2. To always get correct background colors (both in normal and editing modes), configure the Background property in both cell and content view.

Acknowledgements

Contact

http://bigatti.it
@mbigatti

bmxswipablecell's People

Contributors

ashfurrow avatar bomjkolyadun avatar irtemed88 avatar mbigatti avatar mbinna avatar ryumer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmxswipablecell's Issues

Button in cell not responding to tap

Thank you so much for this amazing library!

I'm trying to implement a button in scrollViewContentView. It's supposed to trigger an action that's different from tapping elsewhere on the cell. So far, it's not responding to taps whether or not userInteractionEnabled = YES.

Any ideas?

Problem with accessory views

I've found another issue when using accessory views, while the current logic moves the accessory view using a transform this does not seem to move the underlying UIView and therefore touching the area where the accessory view was located triggers cell selection when the basement view is uncovered.

Item options disappear when cell is being updated.

Environment

Use BMXSwipableCell with NSFetchedResultsController.

Steps to reproduce:

  1. update ManagedObject, that is presented in Cell
  2. when
 - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath 

getting called for event

NSFetchedResultsChangeUpdate
cell is being updated and basementView will be closed if updating row by
 - reloadRowsAtIndexPaths:withRowAnimation:

or if using other method, that configures cell, that was got by
[NSTableView cellForRowAtIndexPath:]
basementView becomes empty.

LayoutSubview crashes in iOS 6.1, iOS 7 working fine

I have a custom cell prototype which consists on a UIView, 3 UILabels. On iOS 7, everything is working as expected but crashes on iOS 6.1.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '{ Rows:
BMXSwipableCell:0x7c92330.Height == 128 + 1_0x7c9b520.marker
BMXSwipableCell:0x7c92330.Width == 640 + 1_0x7c9acc0.marker
BMXSwipableCell:0x7c92330.minX == 0 + 1_0x7c999b0.marker + -0.5_0x7c9acc0.marker
BMXSwipableCell:0x7c92330.minY == 0 + 1_0x7c9a890.marker + -0.5_0x7c9b520.marker
objective == <> + 750:-1_0x7c982c0.negError + 251:-1_0x7c982c0.posErrorMarker

Constraints:
<NSAutoresizingMaskLayoutConstraint:0x7c999b0 h=--- v=--- BMXSwipableCell:0x7c92330.midX == + 320> Marker:0x7c999b0.marker
<NSAutoresizingMaskLayoutConstraint:0x7c9a890 h=--- v=--- BMXSwipableCell:0x7c92330.midY == + 64> Marker:0x7c9a890.marker
<NSContentSizeLayoutConstraint:0x7c982c0 H:[UILabel:0x7c92830(48)] Hug:251 CompressionResistance:750> Marker:0x7c982c0.posErrorMarker
<NSLayoutConstraint:0x7c9acc0 H:[BMXSwipableCell:0x7c92330(640)]> Marker:0x7c9acc0.marker
<NSLayoutConstraint:0x7c9b520 V:[BMXSwipableCell:0x7c92330(128)]> Marker:0x7c9b520.marker
}: internal error. Cannot find an outgoing row head for incoming head 0x7c982c0.negError, which should never happen.'

By commenting out "[self bmx_moveContentViewSubViews]" in layoutSubviews method. Is now running fine in iOS 6.1 and 7.

Forward touch to UITableViewCell

Current version reimplement significant logic to send messages the table view delegate to support highlight / selection. A better option it do let the original UIKit code do that. Investigate if it is possible to somehow forward touches from hosted UIScrollView to UITableViewCell to trigger original UIKit messaging implementation.

Autolayout Issue.

Hi Guys,

I'm using BMXSwipableCell and using autolayout in it getting crash..Means when I add autolayout to controls and make BMXSwipableCell to its baseClass...App gets crashed.
This reason is :- +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint must contain a first layout item'

Tap enabled buttons in cell

I have buttons in my cell but they aren't tappable. Any quick tips on how to use this library and keep my contentView buttons capable of being tapped?

Floating-point equality check

There's a line in your code where you do exact floating point equality testing. If, for example, the basementVisibleWidth is non-integer and non-power-of-two decimal, it will always fail and keep the basement closed.

Does not work with AutoLayout

Hi,

This looked really promising until I noticed it does not play well with Auto Layout. Because it moves the subviews out of the UITableViewCell's contentView and adds them as subviews to scrollViewContentView which causes the NSLayoutConstraints to be lost.

iOS will remove any constraints related to the view when it's removed from it's superview.

It would be nice if this library could detect all the existing constraints and add them back relative to the scrollViewContentView or alternatively try and incorporate the contentView within a UIScrollView and not the other way around as it is current doing it.

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.