How to show editActionsForRowAtIndexPath's buttons of UITableviewCell on cell click - ios

I have used editActionsForRowAtIndexPath to add custom UITableViewRowAction.
I want to auto drag to show this two option(Delete & Cancel) by just to click UITableViewCell (didSelectRowAtIndexPath).
Currently dragging cell from right to left is working but how can I show this without dragging(by just clicking any button on cell),
Is there any method to show this option of a particular cell.
eg.
My Code:
-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// delete action
}];
deleteAction.backgroundColor = [UIColor redColor];
UITableViewRowAction *cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
//cancel action
}];
return #[deleteAction, cancelAction];
}
Note: without using custom design.

Related

editActionsForRowAtIndexPath: action is called automatically when swipe

i'm using tableview with two actions, delete and edit. when i swipe to show the action the first one returned in the array of editActionsForRowAtIndexPath: is called automatically
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// delete ...
}];
deleteAction.backgroundColor = [UIColor redColor];
UITableViewRowAction *edit = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#" Edit " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
// edit ...
}];
edit.backgroundColor = [UIColor colorWithRed:0x2F/255.0 green:0x83/255.0 blue:0xFB/255.0 alpha:1];
return #[deleteAction,edit];
}
here the delete action is called. I want the actions to show when swipe but not to be called without tapping.
For this you need to swipe table row slightly.Then it will show both the action options and actions will be called on tapping only.

How to set the action of UITableViewRowAction

I customized my UITableCellDeleteConfirmationView to change the background color of the button in iOS 8 and above. Following this post, I implemented editActionsForRowAtIndexPath, commitEditingStyle and canEditRowAtIndexPath.
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
RankedSpecies* rankedSpecies = [fetchedResultsController objectAtIndexPath:indexPath];
if ( [self.collectedLeaf.selectedSpecies isEqualToString:[rankedSpecies.Species commonNameFirstLast]] )
{
UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(#"Action to perform with Button 1");
}];
unlabelSpecies.backgroundColor = [UIColor darkGrayColor];
return #[unlabelSpecies];
}
UITableViewRowAction *labelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Label" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(#"Action to perform with Button 1");
}];
labelSpecies.backgroundColor = [UIColor darkGrayColor];
return #[labelSpecies];
}
However, when I push these custom buttons, they do not call commitEditingStyle. According to this post, commitEditingStyle is only fired when you touch the delete button.
Instead of trying to figure out how to fire commitEditingStyle, I have created methods that replicate my commitEditingStyle implementation, removeCollectedLeafLabel. Can a class method be an action? How do I set the UITableViewRowAction to do something when pressed?
when your press button it will call the block.
UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
CALL_YOUR_METHOD_FROM_HERE
}];
unlabelSpecies.backgroundColor = [UIColor darkGrayColor];
return #[unlabelSpecies];

How to set Tableview Cell Movable with option (Share,Done,Delete) Button ? and it's Action ?

I Want Set Movable Tableview Cell with Button Action.And how can i manage button action.
How Can i implement this stuff.
Here i have Attached image i want like this Image.
Thank you in advance
You can do it withoutUsing any third party control, using UITableViewRowAction of default UITableView..
Below is the code snippet...
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:#" Edit " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
// [self callBlockUser];
}];
editAction.backgroundColor = [UIColor lightGrayColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:#"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
// [self callBlockUser];
}];
deleteAction.backgroundColor = [UIColor redColor];
return #[deleteAction,editAction];
}

UITableViewRowAction change backgroundcolor on press

I created an instance of UITableViewRowAction in
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
and I have a handler block when this row action is triggered:
handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
You have a row action parameter that can be used so you do not create retain cycles and you have an index path. I've tried setting the backgroundColor of that new row action like this:
[action setBackgroundColor:[UIColor greenColor]];
But this did not change anything. I also tried setNeedsDisplay on the button object of the row action, but without any luck.
Any idea how I can change the backgroundColor while the row actions are still visible? Thanks
xCoder
Here is my implementation of the same and it works well. It should solve your problem as well..
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *one = [UITableViewRowAction rowActionWithStyle:0 title:#"one" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(#"my first action");
}];
UITableViewRowAction *two = [UITableViewRowAction rowActionWithStyle:1 title:#"two" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(#"my second action");
}];
UITableViewRowAction *three = [UITableViewRowAction rowActionWithStyle:1 title:#"three" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(#"my third action");
}];
one.backgroundColor = [UIColor purpleColor];
two.backgroundColor = [UIColor greenColor];
three.backgroundColor = [UIColor brownColor];
return #[one, two, three];
}

iOS 8 UITableViewRowAction: Swipe Left, Images?

I've just come across this new API on iOS8. I cannot however find any solution on if it is possible to use images instead of text and to allow left and right swipe? Is this even possible? The only implementation I've found is this:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Button1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:#"Button2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
moreAction2.backgroundColor = [UIColor blueColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:#"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return #[deleteAction, moreAction, moreAction2];
}
No, I don't think it's possible to have a right swipe (with a UITableViewCell, anyway). However, you can use an image for the button by setting its background color using colorWithPatternImage:. The width of the button seems to be determined by the length of the title, so if you want to change the width (and not have any visible title), use a title that consists of as many spaces as you need.
in Swift it would be:
deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)
When you are adding images to the swiped view, this answer may be helpful.

Resources