Saturday, May 10, 2025
Alternative Way
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use
No Result
View All Result
Alternative Way
No Result
View All Result

Convenient UITableViewCell subclass that implements a swippable content to trigger actions

Gordon James by Gordon James
October 3, 2021
in World Tech Code
0 0
0
Home World Tech Code

One of the new iOS 11 features is the addition of the UITableViewCell swipeable action targets. While this new feature is a great help for content creators, it can also be a bit of a hassle. For example, you might be creating a tutorial about how to get your app’s scroll view to scroll automatically, but you don’t want to affect the scroll view’s content view or content view controller.

Today I’m going to show you an alternative way to do a UITableViewCell swipe up to trigger some actions. The swipe up gesture is used by some apps to trigger actions like copying something, sending an email, or starting a new screen, but I wanted to do this in a way that is more practical and less complicated.

As I always tell my students, once you understand the basics of programming, you’ve pretty much got the whole thing down. You just have to learn how to apply them.

Table of Contents

Toggle
  • MCSwipeTableViewCell
  • Overview
    • Output mode
    • Switch mode
  • API reference
  • Use
    • Delegate
    • Cell abnormality
    • Percentage change in travel
    • Reset cell position
  • Setting
    • CocoaPods
    • Carthago
  • Compatibility
  • Requirements
  • GitHub
      • Related Tags:

MCSwipeTableViewCell

I’m trying to show how to implement a UITableViewCell, similar to what we see in the very well made Mailbox app for iOS.

Overview

Output mode

The MCSwipeTableViewCellModeExit is the original behavior we can see in the mailbox application. Move the mouse over the cell to make it disappear. At ease in destructive modes.

Convenient UITableViewCell subclass that implements a swippable content to trigger actions

Switch mode

MCSwipeTableViewCellModeSwitch is a new behavior I am introducing. The cell returns after selecting a state, so you can save the cell. It is convenient to quickly change options.

API reference

See the MCSwipeTableViewCell.h header file for a complete listing of the class’s properties.

Use

– (UITableViewCell *)tableView :(UITableView *)tableView cellForRowAtIndexPath :(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @Cell ;

MCSwipeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier] ;

if (!cell) {
cell = [[MCSwipeTableViewCell allocate] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;

// Remove the insertion of the separator from iOS 7.
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
cell.separatorInset = UIEdgeInsetsZero;
}

[cell setSelectionStyle:UITableViewCellSelectionStyleGray] ;

// Set the background color of the cell.
cell.contentView.backgroundColor = [UIColor whiteColor];
}

// Configure views and colors.
UIView *checkView = [self viewWithImageName:@check];
UIColor *greenColor = [UIColor colorWithRed:85.0 / 255.0 green:213.0 / 255.0 blue:80.0 / 255.0 alpha:1.0] ;

UIView *crossView = [self viewWithImageName:@cross];
UIColor *redColor = [UIColor colorWithRed:232.0 / 255.0 green:61.0 / 255.0 blue:14.0 / 255.0 alpha:1.0] ;

UIView *clockView = [self viewWithImageName:@clock];
UIColor *yellowColor = [UIColor colorWithRed:254.0 / 255.0 green:217.0 / 255.0 blue:56.0 / 255.0 alpha:1.0] ;

UIView *listView = [self viewWithImageName:@list];
UIColor *brownColor = [UIColor colorWithRed:206.0 / 255.0 green:149.0 / 255.0 blue:98.0 / 255.0 alpha:1.0] ;

// Set the default color of the resting state as the background color of the TableView.
[cell setDefaultColor:self.tableView.backgroundView.backgroundColor];

[cell.textLabel setText:@Switch Mode Cell];
[cell.detailTextLabel setText:@Swipe to switch] ;

// Add state-based gestures.
[cell setSwipeGestureWithView:checkView color:greenColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState1 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState, MCSwipeTableViewCellMode mode) {
NSLog(@Did swipe checkmark cell);
}] [cell setSwipeGestureWithView:crossView color:redColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState2 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSLog(@Did swipe Cross cell);
}] [cell setSwipeGestureWithView:clockView color:yellowColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState3 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSLog(@Did swipe clock cell);
}] [cell setSwipeGestureWithView:listView color:brownColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState4 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSLog(@Did swipe List cell);
}]

return the cell;
}

Delegate

MCSwipeTableViewCell has a number of delegated methods for tracking user behavior. See the header file for all methods of MCSwipeTableViewCellDelegate.

@Interface MCTableViewController ()

#pragma mark – MCSwipeTableViewCellDelegate

// Called when the user starts swiping a cell.
– (void)swipeTableViewCellDidStartSwiping :(MCSwipeTableViewCell *)cell ;

// Called when the user has finished swiping a cell.
– (void)swipeTableViewCellDidEndSwiping :(MCSwipeTableViewCell *)cell ;

// Called when the cursor passes.
– (void)swipeTableViewCell :(MCSwipeTableViewCell *)cell didSwipeWithPercentage :(CGFloat)percentage ;

Cell abnormality

In MCSwipeTableViewCellModeExit, you may want to delete a cell with a nice fade-in animation. The following rules will give you an idea of how to proceed:

cell setSwipeGestureWithView:crossView color:redColor mode:MCSwipeTableViewCellModeExit state:MCSwipeTableViewCellState2 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSLog(@Deed swipe over cell 😉

// Code to remove a cell…

}];

You can also ask for confirmation before deleting a cell:

__weak MCTableViewController *weakSelf = self ;

cell setSwipeGestureWithView:crossView color:redColor mode:MCSwipeTableViewCellModeExit state:MCSwipeTableViewCellState1 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
NSLog(@Deed swipe over cell 😉

__strong MCTableViewController *strongSelf = weakSelf ;
strongSelf.cellToDelete = cell ;

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@Delete ?
Message:@Are you sure you want to delete the cell?
delegate:self
cancelButtonTitle:@No
otherButtonTitles:@Yes, nil];
[alertView show];
}]

Then edit the UIAlertView action:

#pragma mark – UIAlertViewDelegate

– (void)alertView :(UIAlertView *)alertView clickedButtonAtIndex :(NSInteger)buttonIndex {

// No
if (buttonIndex == 0) {
[_cellToDelete swipeToOriginWithCompletion:^{
NSLog(@Swiped back);
}];
_cellToDelete = nil;
}

// Yes
otherwise {
// Code to delete the cell….
}
}

There is also an example in the demo project, I recommend you take a look at that.

Percentage change in travel

If the default trigger limits do not meet your needs, you can change them with the properties firstTrigger (default: 25%) and secondTrigger (default: 75%).

cell.firstTrigger = 0.1 ;
cell.secondTrigger = 0.5 ;

Reset cell position

You can return a cell to its original position when using MCSwipeTableViewCellModeExit with the -swipeToOriginWithCompletion: method:

[cell swipeToOriginWithCompletion:^{
NSLog(@Cell swipe back !);
}] ;

Setting

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

$ gem install cocoapods

To integrate MCSwipeTableViewCell into your Xcode project with CocoaPods, specify it in your podfile:

pod MCSwipeTableViewCell, ~> 2.1.4.

Then run the following command:

$ pod install

Carthago

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate MCSwipeTableViewCell in your Xcode project with Carthage, specify it in your cartfile:

github alikaragoz/MCSwipeTableViewCell >= 2.1.4

Compatibility

This library does not support autopartitioning, so you must disable autopartitioning in the xib properties.

Requirements

Ali Karagoz

GitHub

https://github.com/alikaragoz/MCSwipeTableViewCellThe iOS API provides an easy way to have content change when the swipe action is performed. Unfortunately, this approach doesn’t work for all cases where the data source (e.g. from an NSFetchedResultsController) is not in the table view.. Read more about uicontextualaction accessibility identifier and let us know what you think.

Related Tags:

what is swipecellkitswipe button ios swiftuicontextualactionuicontextualaction custom viewuitableviewcell swipe custom button swiftuitableviewcell swipe to delete custom button with image swift,People also search for,Privacy settings,How Search works,uicontextualaction,uicontextualaction custom view,uicontextualaction image not showing,trailingswipeactionsconfigurationforrowat,uicontextualaction accessibility identifier,uicontextualaction icon,uicontextualaction handler,uicontextualaction image tint color

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0
ShareTweet
Gordon James

Gordon James

Next Post
A library which provides you with Squircle views to use for buttons

A library which provides you with Squircle views to use for buttons

  • Trending
  • Comments
  • Latest
How To Get Free Internet On Android Without Service

How To Get Free Internet On Android Without Service

March 10, 2022
🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

🥇 +4 Neo Geo Emulators for Android  List ▷ 2021

October 3, 2021

Fix: Notifications not working on Nova Launcher

October 3, 2021
How to Fix OpenVPN Connected but Not Changing IP Address

How to Fix OpenVPN Connected but Not Changing IP Address

October 3, 2021

Setting Up Directory Sync Between On-Premises Active Directory with Microsoft 365 Azure AD

0
🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

🥇 DELETE ACCOUNT from PS4  ▷ Step by Step Guide ▷ 2020

0
🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

🥇 PPTX File Extension  What is .Pptx and how to open them? ▷ 2020

0
🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

🥇 Make a Crossword in Microsoft Word  Step by Step Guide ▷ 2020

0
What to Know About Car Shipping Services

What to Know About Car Shipping Services

May 7, 2025
CS2 Skins-Why Trade Them?

CS2 Skins-Why Trade Them?

May 7, 2025
Alternative Routes: Successfully Exiting Your Wyndham Timeshare Without The Stress

Alternative Routes: Successfully Exiting Your Wyndham Timeshare Without The Stress

May 6, 2025
The Ultimate Seiko Watch Gift Guide

The Ultimate Seiko Watch Gift Guide

May 1, 2025

There's always an alternative Way!
Find us at 4145 Zolynthian Street, Vylorthos, QP 78425
No Result
View All Result
  • Home
  • Latest
    • Latest
  • News
  • World Tech
  • World Gaming
  • Minecraft
  • Guides
  • Contact Us
  • About The Team
    • Privacy Policy
    • Terms of Use

© 2022 - Alternative Way

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT
No Result
View All Result
  • Home
    • Home – Layout 1
    • Home – Layout 2
    • Home – Layout 3
    • Home – Layout 4
    • Home – Layout 5
  • Travel News

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.