In my app, you can slide to delete a row as done here. After sliding, an alert pops up confirming the deletion. If you cancel it, I'd like to slide the row over so that the delete button is no longer visible. Right now I'm doing the following, but there's got to be a better way that looks more fluid.
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation:UITableViewRowAnimation.Right)
disable edit mode on the tableView
objC: self.tableView.editing = NO;
swift: self.tableView.editing = false
Related
I am using https://github.com/CEWendel/SWTableViewCell library to my project.
Certain situation I need to disable the particular button action of swipe cell.
I cannot find any property in their class file. If anyone crossed this, give me answer.
Here I have attaced my swipe options image:
For ex
: I want to disable the share button action.
Let's assume your share button is in the leftButtonsArray. In the method:
- (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state
{
//case:left buttons opened
UIButton *shareButton = leftButtonsArray[theIndexOfTheShareButton];
shareButton.enabled = NO;
}
#karthikeyan You can hide the button for a particular row in tableview by the following code:
- (void)updateRightUtilityButtons:(NSArray *)rightUtilityButtons WithButtonWidth:(CGFloat) width {
_rightUtilityButtons = rightUtilityButtons;
[self.rightUtilityButtonsView updateUtilityButtons:rightUtilityButtons WithButtonWidth:width];
[self.rightUtilityButtonsView layoutIfNeeded];
[self layoutIfNeeded];
}
Add/update this methods to SWTableViewCell.m class, where rightUtilityButtons is an array of buttons you need to display for the particular row.
In case if you want to disable just user interaction you can achieve while adding button into array, just disable user interaction for that button by shareButton.userInteration = NO and then add to array and then pass the array to the method defined above. By this you can be sure that button is disabled.
But please provide the sample code that you have worked so that can update your code directly.
In case if you still didn't get revert back I'll give you the working code directly here.
I am using MGSwipeTableCell in my app. When a cell is swiped open to reveal buttons if I tap on another cell it dismisses the swipe cell (hides the buttons again). I want the previously swiped cell to dismiss the buttons and then select the new cell in one tap instead of two (i.e. tap off and then tap new cell). Is there any way to to do this?
See the description below, I think this delegate function of MGSwipeTableCell might help you.
-(void) swipeTableCell:(MGSwipeTableCell*) cell didChangeSwipeState:(MGSwipeState) state gestureIsActive:(BOOL) gestureIsActive
{
/**
* Called when the user clicks a swipe button or when a expandable button is automatically triggered
* #return YES to autohide the current swipe buttons
**/
}
On MGSwipeTableCell version 1.5.4 or later
cell.touchOnDismissSwipe = YES;
It will dismiss the cell you did swiped and also select the cell you tap
I've implemented tableView:editActionsForRowAtIndexPath:. In response to some of these actions, i want to snap the row action area back closed.
There doesn't seem to be an appropriate method on UITableViewRowAction. I've tried endEditing on both the table and table cell; I'm not sure what to try next.
How do I do snap the action area closed?
To close the edit actions you can either set the tableViews edit state:
tableView.editing = NO
or set it with animation:
[tableView setEditing:NO animated:YES]
Update for Swift 3
I've been looking for a way to do this using Swift 3, and I finally found it:
tableView.isEditing = false
If you do self.tableView.setEditing(false, animated: true), the user will be brought out of editing mode. I think what you want is you want to stay in editing mode but just dismissing the row action. So you can use the following code:
self.tableView.cellForRow(at: cellIndex)?.setEditing(false, animated: true)
self.tableView.reloadData() // this is necessary, otherwise, it won't animate
I have a sidebar in an UITableView which will display after a long press on a cell. The sidebar has some custom buttons for more functionality.
If the user tab on the UITableView, I will check for the location of the point. If it is outside of the sidebar, then I will close it.
The problem here is, if the user try to scroll (its about 100 rows here) the sidebar stays on the exact place. So my goal is to prevent the user from scrolling on the table as long the sideview is present. (I will also highlight the selected row later.)
I created a UIGestureRecognizer:
tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
view.addGestureRecognizer(tapGesture!)
And check the location:
func handleTap(recognizer: UITapGestureRecognizer){
let location = recognizer.locationInView(view)
if !CGRectContainsPoint(contentView.frame, location){
// dismiss
}
I have a delegate which shows me if the sideview is present, but if I try to set:
tableView.userInteractionEnabled = false
I am unable to click on the sideview, so all user interactions are disabled.
Is there a way to disable only scrolling?
So simple just write this
tableView.scrollEnabled = NO;
I've created a UITableView, where I'm able to detect which cell is being pressed. Works great. But it doesn't "let go" of the button, when it has been pressed once. Take a look below.
The button looks like this when the app loads:
When I tap the button, it looks like this: and it looks like this until another cell is pressed. How do I make the button "let go" of the press, so it looks like a tap, and then looks like the first picture again? The button is in a static table view.
I really searched a long time, and it was hard to find a term for "let go of button".
Thank you!
You can do this:
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated: YES];
}
It's a delegate-method that will automatically fire if you've set your ViewController as delegate for the tableView when you select a row.