Git Product home page Git Product logo

swtableviewcell's Introduction

SWTableViewCell

Build Status Coverage Status

An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail Application)

##Usage In your Podfile:

pod 'SWTableViewCell', '~> 0.3.7'

Or just clone this repo and manually add source to project

##Functionality ###Right Utility Buttons Utility buttons that become visible on the right side of the Table View Cell when the user swipes left. This behavior is similar to that seen in the iOS apps Mail and Reminders.

###Left Utility Buttons Utility buttons that become visible on the left side of the Table View Cell when the user swipes right.

###Features

  • Dynamic utility button scalling. As you add more buttons to a cell, the other buttons on that side get smaller to make room
  • Smart selection: The cell will pick up touch events and either scroll the cell back to center or fire the delegate method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

So the cell will not be considered selected when the user touches the cell while utility buttons are visible, instead the cell will slide back into place (same as iOS 7 Mail App functionality) * Create utilty buttons with either a title or an icon along with a RGB color * Tested on iOS 6.1 and above, including iOS 7

##Usage

###Standard Table View Cells

In your tableView:cellForRowAtIndexPath: method you set up the SWTableView cell and add an arbitrary amount of utility buttons to it using the included NSMutableArray+SWUtilityButtons category.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";
    
    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (cell == nil) {
        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        cell.leftUtilityButtons = [self leftButtons];
        cell.rightUtilityButtons = [self rightButtons];
        cell.delegate = self;
    }
    
    NSDate *dateObject = _testArray[indexPath.row];
    cell.textLabel.text = [dateObject description];
    cell.detailTextLabel.text = @"Some detail text";
    
    return cell;
}

- (NSArray *)rightButtons
{
    NSMutableArray *rightUtilityButtons = [NSMutableArray new];
    [rightUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:0.78f green:0.78f blue:0.8f alpha:1.0]
                                                title:@"More"];
    [rightUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
                                                title:@"Delete"];

    return rightUtilityButtons;
}

- (NSArray *)leftButtons
{
    NSMutableArray *leftUtilityButtons = [NSMutableArray new];
    
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
                                                icon:[UIImage imageNamed:@"check.png"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:1.0f green:1.0f blue:0.35f alpha:1.0]
                                                icon:[UIImage imageNamed:@"clock.png"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:1.0f green:0.231f blue:0.188f alpha:1.0]
                                                icon:[UIImage imageNamed:@"cross.png"]];
    [leftUtilityButtons sw_addUtilityButtonWithColor:
     [UIColor colorWithRed:0.55f green:0.27f blue:0.07f alpha:1.0]
                                                icon:[UIImage imageNamed:@"list.png"]];
    
    return leftUtilityButtons;
}

###Custom Table View Cells

Thanks to Matt Bowman you can now create custom table view cells using Interface Builder that have the capabilities of an SWTableViewCell

The first step is to design your cell either in a standalone nib or inside of a table view using prototype cells. Make sure to set the custom class on the cell in interface builder to the subclass you made for it:

Then set the cell reuse identifier:

When writing your custom table view cell's code, make sure your cell is a subclass of SWTableViewCell:

#import <SWTableViewCell.h>

@interface MyCustomTableViewCell : SWTableViewCell

@property (weak, nonatomic) UILabel *customLabel;
@property (weak, nonatomic) UIImageView *customImageView;

@end

If you are using a separate nib and not a prototype cell, you'll need to be sure to register the nib in your table view:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView registerNib:[UINib nibWithNibName:@"MyCustomTableViewCellNibFileName" bundle:nil] forCellReuseIdentifier:@"MyCustomCell"];
}

Then, in the tableView:cellForRowAtIndexPath: method of your UITableViewDataSource (usually your view controller), initialize your custom cell:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString *cellIdentifier = @"MyCustomCell";
    
    MyCustomTableViewCell *cell = (MyCustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier 
                                                                                           forIndexPath:indexPath];

    cell.leftUtilityButtons = [self leftButtons];
    cell.rightUtilityButtons = [self rightButtons];
    cell.delegate = self;
    
    cell.customLabel.text = @"Some Text";
    cell.customImageView.image = [UIImage imageNamed:@"MyAwesomeTableCellImage"];
    [cell setCellHeight:cell.frame.size.height];
    return cell;
}

###Delegate

The delegate SWTableViewCellDelegate is used by the developer to find out which button was pressed. There are five methods:

// click event on left utility button
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index;

// click event on right utility button
- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index;

// utility button open/close event
- (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state;

// prevent multiple cells from showing utilty buttons simultaneously
- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell;

// prevent cell(s) from displaying left/right utility buttons
- (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state;

The index signifies which utility button the user pressed, for each side the button indices are ordered from right to left 0...n

####Example

#pragma mark - SWTableViewDelegate

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
            NSLog(@"check button was pressed");
            break;
        case 1:
            NSLog(@"clock button was pressed");
            break;
        case 2:
            NSLog(@"cross button was pressed");
            break;
        case 3:
            NSLog(@"list button was pressed");
        default:
            break;
    }
}

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
            NSLog(@"More button was pressed");
            break;
        case 1:
        {
            // Delete button was pressed
            NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
            
            [_testArray removeObjectAtIndex:cellIndexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[cellIndexPath] 
                    withRowAnimation:UITableViewRowAnimationAutomatic];
            break;
        }
        default:
            break;
    }
}

(This is all code from the included example project)

###Gotchas

Seperator Insets

  • If you have left utility button on iOS 7, I recommend changing your Table View's seperatorInset so the seperator stretches the length of the screen
 tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); 

##Contributing Use Github issues to track bugs and feature requests.

##Contact

Chris Wendel

Licence

MIT

swtableviewcell's People

Contributors

addoshi avatar adrian2112 avatar alex9779 avatar cewendel avatar clementua avatar dacohn avatar danielebogo avatar dcwither avatar dimavartanian avatar donnellyk avatar ebgraham avatar fernandospr avatar gabriel avatar harlanhaskins avatar hongrich avatar jschmid avatar jtdaugh avatar jtmilne avatar laud avatar maciekish avatar mergesort avatar mslathrop avatar onevcat avatar philipdnichols avatar qszhu avatar rex-remind101 avatar wdragen avatar wokalski avatar yuklai avatar yusuga 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  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

swtableviewcell's Issues

Very slow cell creation when used in custom tableViewCell that's created programatically.

I'm subclassing SWTableViewCell and creating my cells programmatically without using storyboards or nibs/xibs at all. The cell creation is very, very slow, making the initial tableView scrolling almost impossible. Once all the cells are created, it scrolls fine.

I tried this and it seems to fix the problem, but it's a hack:

    [self performSelector:@selector(initializeSwipeButtons) withObject:nil afterDelay:1.0f];

Basically, I create the cell with rightUtilityButtons and leftUtilityButtons set to nil and then call that method to initialize them with a 1.0 second delay.

Any idea why this is happening?

Clear background issue

I have a tableview that uses a clear background. After swiping left/right and the buttons show up and when you swipe back to hide the buttons, the buttons just stay on the screen. Are there any workarounds for this?

Thanks.

Change target to 6.0 instead of 6.1

It is a pity that the target is 6.1 because the library works on 6.0. I think it would be a simple and nice change if you could change the deployment target to 6.0 (and update the pod .

[!] The platform of the target Pods (iOS 6.0) is not compatible with SWTableViewCell (0.2.2) which has a minimum requirement of iOS 6.1.

Is it a miswriting in layoutSubviews?

i think scrollViewButtonViewLeft.frame's origin should start from 0 ,but in the code ,it's start from leftButtonWidth,but because the left button frame will adjust in scrolling ,so this will do nothing wrong, but I think it's better to fix it right:)

  • (void)layoutSubviews {
    [super layoutSubviews];

    self.cellScrollView.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), _height);
    self.cellScrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds) + [self utilityButtonsPadding], _height);
    self.cellScrollView.contentOffset = CGPointMake([self leftUtilityButtonsWidth], 0);
    self.scrollViewButtonViewLeft.frame = CGRectMake([self leftUtilityButtonsWidth], 0, [self leftUtilityButtonsWidth], _height);
    self.scrollViewButtonViewRight.frame = CGRectMake(CGRectGetWidth(self.bounds), 0, [self rightUtilityButtonsWidth], _height);
    self.scrollViewContentView.frame = CGRectMake([self leftUtilityButtonsWidth], 0, CGRectGetWidth(self.bounds), _height);
    self.cellScrollView.scrollEnabled = YES;
    self.containingTableView.scrollEnabled = YES;
    self.tapGestureRecognizer.enabled = YES;
    }

Cell does not become Selected, gets deselected immediately

I have subclasses SWTableViewCell with custom cell.

Wen Cell is tapped the selection never displays.

I believe it is caused by this code in SWTableViewCell:

- (void)scrollViewPressed:(id)sender
{
    SWLongPressGestureRecognizer *longPressGestureRecognizer = (SWLongPressGestureRecognizer *)sender;

    if (longPressGestureRecognizer.state == UIGestureRecognizerStateEnded)
    {
        // Gesture recognizer ended without failing so we select the cell
        [self selectCell];

        // Set back to deselected
        [self setSelected:NO];
    }

It calls [self SelectCell] which calls tableView:didSelectRow
( DidSelectRow sends selected:YES to the Cell.)

and then on the next line immediately sets it to deselected with [self setSelected:NO]; Net result: the Cell remains deselected.

I believe the [self setSelected:NO] is unnecessary.

Custom cell programmatically

Hello,

I just use custom cell, but without interface builder, I just subclass the UITableViewCell , how can I still implement SWTableViewCell ?

Thank you.

Feature request - To automatically close the swiped cell.

Hi,

It would be cool to be able to automatically close the current swiped cell when a new one is swiped.

It could also be interesting to be able to automatically close the current swiped cell when the user scrolls the UITableView.

Thanks for this project.

problem with SWLongPressGestureRecognizer

Hi,

How can I use SWLongPressGestureRecognizer in my cell to use UIActionSheet?!?

I added this code in SWTableViewCell.m:

// *************************************************************************************************
SWLongPressGestureRecognizer *longPressRecognizer = [[SWLongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(longPress:)];
longPressRecognizer.minimumPressDuration = 0.5;
[cellScrollView addGestureRecognizer:longPressRecognizer];

self.longPressRecognizer = longPressRecognizer;

// *************************************************************************************************

but works only when I put the cell to the left or to the right

Multi Select in editing mode

You can't multi-select cells while the tableview is in editing mode.

Absolutely love your SWTableViewCell, but this is a super necessary feature.

Allow to set amount of cell shown when swiped

I would like to set how much of the original cell is shown once swiped, in one app I would like to override it so that once the cell is swiped, they can only see the icons and not the cell.

Is this possible and if not how can I override to create this behaviour ?

canEditRowAtIndexPath being ignored.

Bug:
If you want to only some cells to be editable it wont work to use the method:

  • (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

Steps to reproduce:

Change the method in the example app to return NO and still all the cells are editable.

Custom cells?

I tried using this with a custom storyboard table prototype cell. But as I change the parent from UITableViewCell to SWTableViewCell, the cell is rendered as a blank cell.

Does it work with custom cells or only basic?

SWTableViewCell Memory Leak (delegate is not weak!)

The delegate problem of SWTableViewCell is not "weak"... It is just (id)

I start to notice it during profiling the app and just can not figure out why the cells can not be released, so is the controller. And the memory gets pile up. Finally I find that delegate property of SWTableViewCell is only id. Weird..

I am not sure is there a reason to not set it as a weak property?

didSelectRowAtIndexPath doesn't work

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

Dynamically change cell height ?

Hi

Now with iOS 7 dynamic font size, Since the cell sets it's height according to the tableView row height on init. the cell height dose not update when user changes font size.
Can you fix that please ?

Many thanks
Shani

Row Height

When the rowHeight is set by "heightForRowAtIndexPath" the contentView of the cell is not set to this height.

See this picture:
bildschirmfoto 2013-11-07 um 10 51 09

How to fix this? Thanks a lot for this amazing framework!

Please update podspec ref #34

Hi Chris,

can you update your podspec with right tag so that we can point to the right version with #34 fixed !?

Thanks for your great work :)

๐Ÿš€

Cell's background color doesn't change

If you change the background color of a cell in cellForRowAtIndexPath it wont change in the app.

Steps to reproduce:
Add the following line in cellForRowAtIndexPath in the example project:

[cell setBackgroundColor:[UIColor blackColor]];

You'll see that the cell background doesn't change.

I've tried to change the code in the SWTableViewCell.m to make it work but had no success. If you change the code in the .m file where it says:

// Create the content view that will live in our scroll view
UIView *scrollViewContentView = [[UIView alloc] initWithFrame:CGRectMake([self leftUtilityButtonsWidth], 0, CGRectGetWidth(self.bounds), _height)];

scrollViewContentView.backgroundColor = [UIColor whiteColor];

change the last line to:

scrollViewContentView.backgroundColor = [self backgroundColor];

You can change the background, but it causes some weird behaves.

Subclassing SWTableViewCell Causes Cell to Be Empty!

I am attempting to subclass SWTableViewCell to gain its capabilities, but when I do, all of my cell's subviews disappear. All that displays is an empty cell.

What could be causing this issue?

Here is the header for my SWTableViewCell subclass:
screen shot 2014-01-07 at 11 09 48 am

Here is my prototype for my subclass:
screen shot 2014-01-07 at 11 10 08 am

View hierarchy for my cell prototype:

screen shot 2014-01-07 at 11 14 34 am

I specified the Custom Class:
screen shot 2014-01-07 at 11 10 24 am

I specified my reuse identifier
screen shot 2014-01-07 at 11 10 34 am

Here is the code that create's my SWTableViewCell subclass. Note that if I make CourseCell (my subclass) a subclass of UITableViewCell instead of SWTableViewCell and comment out the SWTableViewCell-specific code, it displays fine.
screen shot 2014-01-07 at 11 11 26 am

Here are the empty cells when I subclass SWTableViewCell:

screen shot 2014-01-07 at 11 24 22 am

Here is what it should look like and does look like when I do not subclass SWTableViewCell.

screen shot 2014-01-07 at 11 27 57 am

backgroundColor super implementation not called

Line no 292 SWTableViewCell.h
#pragma mark UITableViewCell overrides

  • (void)setBackgroundColor:(UIColor *)backgroundColor
    {
    [super setBackgroundColor:backgroundColor]; // this line was missing
    _scrollViewContentView.backgroundColor =backgroundColor
    }

Cell Accessory Item

When swiping the cells Accessory item (check, disclosure indicator) stats in place and does not move

Pod contains AppDelegate.h

After I installed pod, it became impossible to build the project.
Please remove AppDelegate.h from pod.

Sometimes the rightUtilityButtons aren't shown

The library works perfect and I like using it. However, sometimes (without a particular reason) I can slide, but I cannot see buttons. How can this be?

It's not a particular text I'm printing out in the tables. They are sometimes just not there after I deleted already one. How could this be? After every deletion I refresh the array with the contents and reload the tableView data. It's happening on totally random occasions.

Highlight...

Hi,
Compliments for this great work, but i wanted to know if issue of highlighting cell on 0 STATE will be implemented soon?

Thank you!

SWTableViewCell clear background colour causing error

This code works ok, but when I change the background colour of the cell to clear from white the right buttons will not swipe away out of the view. Is there a way to fix this?

SWTableViewCell.m

  • (void)setBackgroundColor:(UIColor *)backgroundColor {

    self.scrollViewContentView.backgroundColor = [UIColor clearColor];

    }

Cell content is not getting swiped

I'm trying to implement SWTableViewCell into my UITableView with a custom cell from a xib-file. But the this that is happening is that the cell content is not swiped over to the left side like it should. As a result of this the content overlaps the buttons. See image:

bild

It seems to be an issue that occurs when I use a custom cell design through a xib-file. Does anyone have a similar issue?

Slide back too slow

When sliding the cell back to normal it moves too slowly. When the gesture ends it should quickly slide back to the original position. Test by doing a slow drag of the cell.

Only Swipe Gesture will work

Great job. Its exactly what I was looking for. But if I implement this cell, I can only have right swipe or left swipe. Selecting a row gesture will not work. Can you improve this so that other gesture like selecting the cell?

Gesture recognizer inside the cell is not working. Please suggest whether my solution is fine.

In SWTableViewCell, there are two properties
tapGestureRecognizer and longPressGestureRecognizer.

So the problem I am facing is that they consume the events and cancel other events so my label becomes not clickable. E.g. I need to use TTTAttributedLabel for detecting links.

Property cancelsTouchesInView of UIGestureRecognizer by default is YES and I guess maybe we need to change it to NO.

Should it be "swipeable"?

Christopher, awesome library. Thanks! Can't wait to use it. You've probably heard it already, but should it be "swipeable", not "swippable"?

When edit model, how to deal the system's delete button?

When "- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
} "

and "[_tableView setEditing:YES animated:YES];" , how to deal the system's delete button?

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.