I am trying to duplicate the functionality found in the Settings app when managing the Spotlight search options:
I need to be able to rearrange the order of a tableview without an editButton and will need to be able to select/deselect a cell, having the checkmark appear to the left of the cell label.
When I use the following code:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
return 3;
}
I get this:
This works, but I was wondering if there was any way I could customize the editing style so that the checkmarks are more like they are in the spotlight settings (The red checkmarks look like items are being selected for deletion).
Possible duplicate of: How can i custom UITableViewCell editing style?, but no one seems to have answered it.
Set the editing style to UITableViewCellEditingStyleNone. Instead, create a checkmark image and a "blank" image (the same size at the checkmark image) and use these to set the cell's imageView.image property. You will need to keep track of which cells are checked or not. Toggle this state and the image view from the didSelectRowAtIndexPath method.
Related
I have UICollectionView in my iOS app and I am using Swift. I want to make UI like below:
I this UI when "Select" button is not selected (in first image) Tab bar is visible, but when "Select" button is selected (in second image), a new bar is visible. This is used for multiple cells selection. I just want to know, Is this functionality available by Apple (built in) or I have to make it manually (by myself)? (I have searched, but could not find)
Collection View gives functionality to select multiple cells. Just write this code and you will be able to select multiple cells.
yourCollectionViewName.allowsMultipleSelection = true
I have a UITableView with some data, and I'm hoping to put in the top row or section a cell (call it, "Add Record" or something), which is always in edit state, so that it always displays the system insertion control. Is this possible? If so, how?
I've searched all around for this. Apple's documentation lists a setEditing(_:animated:) method on UITableViewCell. I used both that and setting isEditing to true on the cell on load, and it appears to be in isEditing state because the table wouldn't let it be selected until I turned on 'single selection in edit state'. But no insertion or deletion controls show up, and the delegate's tableView(_:editingStyleForRowAt:) is never called.
The cell looks fine if I call setEditing(_:animated:) on the table view itself, but that sets every cel to editing, deletion and all! That's not what I want.
I suppose I can just use a normal cell, and use an image of an insertion control, but I'd rather use Apple's system one if possible (since they might change). Aside: I could always load up an editing table on load and cache a snapshot of an editing control, but that's waaaay more work than its worth!
Is what I'm going for even possible? Do you understand what I'm going for? Any advice you could provide would be very helpful.
You can try the following approach:
Keep using setEditing on the UITableView itself.
To show the editing controls only for a specific cell, implement the
canEditRowAtIndexPath method of the
UITableViewDataSource delegate and return true only for the cell that you wish to allow editing for.
At this point your specific cell will show the editing controls, but the cells are not selectable; you'll need to set allowsSelectionDuringEditing on your table-view
to allow the cells to get selected. Next, you will probably want to
prevent the editing cell from being highlighted by implementing
shouldHighlightRowAtIndexPath delegate method and return true for
all cells except for the cell that you want to keep in editing mode.
Other possible solutions:
Create your own UITableViewCell and implement the editing UI yourself (which will always be visible), then use this cell where you need it.
Use another UITableView with a single cell which will always be in editing mode and place it above your other table so it would appear to be the same table. It's a possible solution but most likely an overkill.
I have a UITableView with a section where I'd like to show the drag/reorder-button depending on a setting from another section. I have implemented canMoveRowAt: and moveRowAt:to:, but the tableView only shows the drag-icon when tableView.isEditing = true.
I also need the ability to delete rows, but I want that functionality to only appear in edit-mode, so simply constantly being in edit-mode isn't any good for me.
I've tried playing around with the cell.showsReorderControl, but this also just hides and shows the button when in Edit-mode, and doesn't affect the cell in non-Edit mode.
Is there a way to show the reorder-button when not in Edit-mode?
Is it possible to customize the multiselect edit mode? So instead of the default selection icon (the circle with the checkmark), I need to show a custom one, with selected and unselected states.
I also need to indent the cell more to the right.
Obviously I would like to use as much as possible of the system provided animations.
HEre's a screenshot of the sample editing mode of uitableview. (My cell is much more complicated :)
Thanks,
Jason
You can customise the cell.. create a UITableViewCell with a UIButton and set the custom images you want for the selected and default states and load this custom cell in cellForRowAtIndexPath:
I iOS 5 Apple added functionality to make it easier to make a multiple selection table view through:
self.tableView.allowsMultipleSelectionDuringEditing = YES;
When the table is in edit mode I can see the multiple selection mark but when I check it, it does not display the usual red checkmark to denote it is selected. So I assume I have to programatically access that UIView and set the appropriate image.
So my question is, how can I access the UIView that displays the circle that represents if the cell is selected or not?
(source: winddisk.com)
There is no need to programatically access the UIView and update it with the checkmark.
The solution to the problem was way easier, here it is:
Cells not getting selected in UITableView with allowsMultipleSelectionDuringEditing set in edit mode