Can't press the button in UITableViewCell after iOS 15 update - ios

I have a UITableView that rapidly update the data and there is a button in the UITableViewCell. From iOS 11 to 14, it works perfectly but after the iOS15 update, the button is broken.
It seems to be untouchable while the cell is updating. So, I can't touch the button
It need to touch on it a lot of times to make the button action fired
When it fired, some time is fire as another cell context. For example: I press the button on cell 1 it should send the sender from cell 1 to the responder but it send the sender from cell 2 instead
The button was embedded as
cell.contentView.isUserInteractionEnabled = true
cell.button.addTarget(self, action: #selector(self.doSomething(sender:)), for: .touchUpInside)
Anyone has some suggestion for me? Thank you
UPDATE
I found the solution is use reconfigure instead of reloadData for UITableView
let indexPaths = tableView.indexPathsForVisibleRows!
if !indexPaths.isEmpty {
tableView.reconfigureRows(at: indexPaths)
}

cell.contentView.isUserInteractionEnabled = true
Remove this line in your code.

Related

Segmented control in tableCell

I have a problem with segmented control in table cell. No action of Segmented control
segmentedFilter.addTarget(self, action: #selector(ProductListFilterCell.filterSelected), forControlEvents: .AllEvents)
Target function:
func filterSelected() {
if let order = ProductListViewModel.OrderBy(rawValue: segmentedFilter.selectedSegmentIndex), let change = orderChanged{
change(order)
}
}
Is it possible to have segmented control in table cell ?
It is incorrect to call addTarget in prepareForReuse, because this method is called when the cell is no longer needed. Only reused cells would have a selector on them.
The second problem is the target: you are passing self, which is the data source for the table, but the selector refers to the cell. If you bring up a reused cell by scrolling up and down several times, your control would trigger the event, and the app would crash with unknown selector message.
You can fix this by moving the method into the data source class, adding target in cellForRowAtIndexPath, and removing the target in prepareForReuse.
segmentedFilter.addTarget(self, action: #selector(ProductListDataSource.filterSelected), forControlEvents: .AllEvents)
// ^^^^^^^^^^^^^^^^^^^^^^

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!

Custom cell in UITableView (iOS 9)

I have simple tableview with custom cell that contains uibutton. After update to iOS 9 GM or 9.1 Beta 1(it doesn't matter) button on cell stopped to response on touch. I have also create IBAction method inside cell class and it's also doesn't work at all
cell.username.setAttributedTitle(attrNameString, forState: .Normal)
cell.username.tag = notify.likeObject.likedUserId.integerValue
cell.username.addTarget(self, action: "showProfile:", forControlEvents: .TouchUpInside)
OK, I found a fix. The issue when I am creating cell from XIB. So I added self.contentView.userInteractionEnabled = false to cell class and it's solved the issue

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

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