Making UITableView with delete buttons visible for all cells - ios

Normally one can create a UITableView with cells that allow the user to reveal the red "Delete" button on the right side of the cell by swiping that cell or by tapping a knob visible on the left side of the cell.
However, I would like to create a UITableView which has all cells with visible "Delete" button by default (no swiping / tapping knob necessary). Is it possible to do utilizing the standard Cocoa Touch methods?
(I know I can define my own button in a custom UITableViewCell, but I'd rather use a standard method if possible...)

Call [tableView setEditing:YES animated:NO] in your view controller's -viewDidLoad implementation.

Well.. NO. Actually the red minus on the left side is the constant-visible solution in Cocoa. I don't believe you get the right delete button without ugly hacking of the tableView.
So probably you have to make a custom solution. But you need no subclassing here. You can just use a regular UITableViewCell and set a UIButton as the accessoryView.

Related

Can I make only a certain portion of a tableview clickable?

I'm trying to add a like button in a tableview but If I click anywhere in the tableview, it immediately goes to the detailsVC. I want to make it so when you click that like button, only that is selected. Is there a way to make it so only the top half of the tableview can be selectable or have interaction enabled, and put the button below? Or is there another way to do this. Is there a workaround or a method I am missing. Thanks
Are you sure the UIButton is added correctly to table view cell's .contentView?
Can you see it? If so it will intercept the touch events and tableview's delegate didSelectRowAtIndexPath won't get called (even if there's no handling connected to the button). If you want make the button occupy specific area of the cell you can either:
Design your cell in Interface Builder and make it a part of Storyboard/Xib
Do autolayout of the cell programmatically
Override cell's layoutSubviews and manually setup the frames

Limit the cell selection area in uitable view

I have a custom cell in table view, which allows multiple selection. Can i limit the cell selection area of a custom cell. Can i enable selection area to only the left side of the cell not the entire cell.
Please share your thoughts.
In your UITableViewCell subclass override pointInside:withEvent: method and return YES only for the points inside the area you want.
Yes, the way you want can be implemented, You make a button on left side of your cell. So Whenever you click on button your selected are will be enabled.
You do not need to implement any logic in UITableView DidSelectRowForIndexPath.
Need to manage in your button.
You can add a UIButton on the left side of your cell, by this way you can easily handle the selection of UIButton by using its tag value.
In the custom tableView Cell. The are which you want to be non clickable add a button to that area and if a tap is registered in the button the didselectitem at indexPath would not be called I have done a similar implementation myself.
My TableView Implementation

Disabling touch interaction of Spaces between Custom table view cell

I use custom cells of subclassing UITableViewCell in a table view. And There must be space between cells. I succesfully add the space with adding a subview that I called SpaceView into the content view. But When I touched the spaceView, it is perceived as I touched the cell. And didSelectRow method called. I tried to set spaceView's UserInteractionEnabled==NO. But It doesn't work.
So my question is; Is this the right way I used to add space between cells ? Should I try to add cells for making the space ? or If its the right way, How can I prevent calling "didSelectRowAtIndexPath" method when I touched spaceView ?
like Inder said below, u can use an UIButton to solve the issue.
1) in your custom cell: at the bottom of your custom cell add a blank UIButton with the height u actually need between cells, and customize its background color according to your needs.
2) in cellforrowatindexpath: disable button of each cell. (or you can also do that in Interface Builder of previous step)
result: u have a clear disabled button that will appear as required space between cells.
Make your spaceView as UIButton (I guess it's UIView right now)
When you add UIButton that touch will be consumed by the button thus touch won't be passed to it's parent.
OR
I'm not sure if it will work or not, you can add tap gesture to your spaceView

UITableView edit mode shifting of cell

I have an UITableView with a custom cell and a custom button for the entering the edit mode as well as a custom accessory button. Everything is working but I want the UIImageView with two other UILabels adjacent to it within the cell to be at its X position but only want the "ADD QTY" UILabel to shift its X position to make room for the accessory button.
If you don't want the contents of the UITableViewCell to shift, implement the method
- tableView:shouldIndentWhileEditingRowAtIndexPath:
and make it return NO. This method is a part of UITableViewDelegate.
To make the ADD QTY move left, you will need to make a custom animation, I think. Animate the label for ADD QTY in this method
- tableView:willBeginEditingRowAtIndexPath:
There is a similar question here. Check it out and tell me if it works. Cheers!

UITableViewCell covering delete button on swipe left

I am posting this question, specifically related to iOS 7.
When I swipe cell to left, the delete button appear correctly, but the cell is not moving left enough, which results in the delete button being covered by the cell for nearly half of its width.
The cell is a class extending UITableViewCell, and in Storyboard there's a UIView with some child views in it, but for the rest it is just a plain cell.
The custom class is not implementing any drawing mechanism.
Unless you have some custom code configuring your cell, I would remove the code for this and add it back. There has to be something that you've written in your code to cause this to happen. Usually, this functionality works right out of the box. Post your code so that we can see what's causing the issue.

Resources