Another Button at UITableView Editing Mode - iphone

I need an additional button next to the Delete button when in editing mode of UITableView Cells. Any suggestions for the purpose is appreciated. Thank You.

I would suggest you first subclass UITableViewCell. In the respective init method you create the button and add it to the contentView as a subview. Make the button hidden. After that you overwrite layoutSubviews and position the button on your content view by setting the frame property of the button. Then also subclass willTransitionToState: and check if the state is UITableViewCellStateShowingEditControlMask. If that's the case make the button visible. If not hide it.
Note: If you add an additional button to the UITableViewCell you also need to adjust the textLabel frame and other stuff to not overlap the button's rectangle.

cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
or some other value than "check"
or
cell.editingAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoDark];
or with some other value than the info button, with it's target set to something appropriate
an accessory view trumps a type

Related

Why doesn't UIButton showsTouchWhenHighlighted work when the button is on a UITableViewCell?

I put a UIButton on a UITableViewCell and set its showsTouchWhenHighlighted property to YES. The cell's selection style is UITableViewCellSelectionStyleNone. I have a selector that gets called when the button is tapped and it's working fine, so the button is getting the touch events fine. However, button doesn't show the highlight effect when touched.
When I put this button on a UIView, the highlight effect works.
How can I make this work when the button is placed on the cell?
Are you adding the button to the cell or cell.contentView? The contentView property behaves more like a regular UIView, that might solve your problem.
You need to set 'delaysContentTouches' to NO on the Table View

Make UIView work like a UIButton

I built a Custom Cell in IB and in it created a view that represents a button. It has Labels and ImageViews in it.
I want to know if there is a way to make that view act like a button. That is, show a shadow and call a method when is pressed.
Yes. Just implement tableView:didSelectRowAtIndexPath: and you can do everything you could do in a button action #selector.
As for the shadow and the rounded rectangle button feel, if you use a single cell in a section with UITableViewStyleGrouped, it will be pretty close.
The best is to make it a button. You can use UIButtonTypeCustom and set the background to the cell you've created.
You can use UITapGestureRecognizer and pass the event through a delegate or use UIControl which is a subclass of UIView but with UIButton tap events like touchUpInside and so, and then pass the event with a delegate to your view

Allow input in a UITableViewCell

So I have a UITableView (its in a UIPopOverController if that matters), and I want the user to be able to edit the content of the tableView. I added a UINaviagationController, the tableView also has a title and an edit button. Essentially what I'm asking is, when the user taps the edit button, how can I add like UITextViews to some of the tableViews and in one of the cells, a UISegmentControl and a UITextView.
Thanks in advance
just add them as subviews of the cell, set correct frame to make subviews inside the cell

Determine whether UITableViewCell is editing from "swipe" or "self.editButton"

I'm trying to determine whether a UITableViewCell subclass is in edit mode from a user's swipe (in which case I don't need to indent my subviews) or from the user pressing the "Edit" button associated with the UITableViewController. (In which case I do.)
I know it's possible from a cell's perspective, since the self.textLabel view automatically indents properly. I have tried:
-(void)layoutSubviews {
[super layoutSubviews];
CGRect labelFrame = self.textLabel.frame;
labelFrame.origin.x += 5;
myCustomUILabel.frame = labelFrame;
}
But my custom label does not properly indent. (Though the self.textLabel view does?)
I would like to avoid the following:
Providing the cells with a reference to the parent table.
Overriding methods in the UITableViewController class to let the cells know whether they are being edited individually or the entire table is editing.
You can override willTransitionToState: in your UITableViewCell subclass. When the "Edit" button is pressed the state will be UITableViewCellStateShowingEditControlMask(=1) and when swiping it will be UITableViewCellStateShowingDeleteConfirmationMask(=2).
You should not be doing the indentation manually. The UITableViewCell will do it for you!
All you have to do is make sure that you add your subviews to 'contentView' of the UITableViewCell. This is the reason why self.textLabel indents properly as you have identified.
Look at the documentation of contentView property for a UITableViewCell:
The content view of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

removeFromSuperview only removes view from last cell

I have a UITableView set up with a custom delete button which consists of a UIButton (btnDel) added as a subview to the UITableView's cells. The delete button is added as a subview when my edit button is pressed. This works well but when I try to remove the subview using:
[btnDel removeFromSuperview];
It only removes the button from the last cell and the other cells still retain the now removed button. I've tried this in many different ways and still can't figure it out. I've tried using functions such as turning the opacity of the button to 0 or setting Hidden to YES, but like the removeFromSuperview, it only effects the button in the last cell with the others staying the same.
Any help is greatly appreciated and if anymore of my code is needed let me know.
If you don't keep references you can't tell which button belongs to which cell.
You might want to subclass UITableViewCell so that your cells have a property which points to the button (assign the button to the property right after instantiating the button). You could then use this property to access (enable, disable...) the buttons later on.