Table View Press, how to "let go" of button? - ios

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.

Related

Select a cell by UIButton - CollectionViewCell - Swift

I'm using collectionView, and I customized the collectionViewCell in a separate class with type (collectionViewCell). I want to perform an animation when user clicks on a cell. So, I created a UIButton in collectionViewCell and I customized it to cover the whole cell.
button = UIButton(frame: self.frame)
button.addTarget(self, action: "scaleToSmall", forControlEvents: .TouchDown)
self.addSubview(button)
Right now, the animation works perfectly, but the issue is I lost the ability select the cell, and the function didSelectItemAtIndexPath does not call anymore
I found out how to get the indexPath of the cell that has clicked,
But how can I call didSelectItemAtIndexPath again and tell it this cell is selected in order to perform the next action (segue to another ViewController) ???
Thanks in advance!!
You said that you created a button that covers the whole cell, if I have that right. Because of that, didSelectRowAtIndexPath won't do anything because that button is covering the whole cell. Take the Twitter app, for example. You can tap on the cell to open the tweet or you can tap on the user's profile image to open their profile. In this case, it's like you have the profile picture button covering the whole cell. Maybe you can set the animation in didSelectRowAtIndexPath or make the button smaller.
Hope this helps!

How to refresh individual UITableViewCells?

I'm having UITableView with few UITableViewCells,
Which plays Different Audio files based on their index path.
I'm showing play/pause button in UITableViewCell.
on play button click in a UITableViewCell,i wanted to reset play button state for last played cell to default(Play).
Storing index of cell in which the play button tapped would do the thing,but we need to reload all the UITableView,Instead of reloading entire UITableView,can't we refresh/reload individual UITableViewCells?
Any help will be appreciated,
Thanks in-advance.
Two step:
1.find get the press row by rewrite your UITableCellView's button's action method
2.update the press row's image
Abstract tip: When using table views have every case implemented in its cellForRow method, that is in its data source. After any change of state or actual data just reload the table with reloadData.
Work for me every time.
More detailed: In your case - have a global index var to show which row is 'playing' now. In cellForRow check if current and global indexes match and show the right button.
Note, that you can also assign tag to any view (buttons also), this can be useful to know which row each button belongs to.
if you have IndexPath of selected cell; then you can get the cell by
UITableViewCell *cell = [UITableviewObj cellForRowAtIndexPath:selIndexPath];
now you have reference to cell; you can change cells content. i would suggest not to change height of the cell through this process.
If I understand correctly, when a user taps a Play button in a different cell, you want to pause the one currently playing and play the new one. The previous cell image should go back from Pause to Play.
In your code where you change Play to Pause and start playing, save an Index path of that cell. Next time Play is clicked check if you have an Index path saved, get the cell and reset the image on it. Something like this:
tableView:didSelectCell {
if (lastPlayingCellPath) {
MyCell *cell = [tableView cellForRowAtIndexPath:lastPlayingCellPath];
[cell setPlayImage];
}
// Play Audio and change current cell image to Pause
lastPlayingCellPath= selectedCellPath;
}
The above is pseudo code, but you should get the idea.
EDIT: From the comments I figured that your custom UITableViewCell subclass handles the tap event. You could fire a notification that you are starting to play. Every cell would subscribe to that event and reset the state of it's button. So you could do something like this in your subclass
- (instancetype)init {
// standard init code
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willPlay) name:#"CellWillPlayNotification" object:nil];
}
- (void)willPlay {
[self setPlayImage];
}
-(void)buttonTapped {
[[NSNotificationCenter defaultCenter] postNotificationName:#"CellWillPlayNotification" object:self];
// Do your standard handling of the tap
}

Pressing a UITableViewCell when a cell is currently swiped open

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

ios - makes appear all cell delete button by an action

I have a table view (filled by customs cells) and my idea is have a tabbar button (such as "edit button"). Pressing on it, in all row, the button cancell will appear. Is it possible?
You can create the code for the button (you know... UIButton* button = [UIButton alloc]init];) in your cell and set it to Hidden = YES, then add a BOOL to check if the "edit button" was pressed, lets name it BOOL editActive, then when the button is pressed you will check the editActive, if its NO then the Hidden value of the button will be NO and you reload your table with [yourTableView reloadData], otherwise, if editActive = YES, then you must hide your "Cancel button" in the cell and once again use [yourTableView reloadData]

Unslide Delete Button UiTableViewCell

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

Resources