TableView editing style - ios

I've got a tableView with entries which the user should be able to edit. The special thing is, the tableView has a "right detail" style (a number) and I want this right detail to be replaced (animated if possible) with the standard disclosure indicator accessory, when the user hits edit.
How can I do this? Thank you!
Update: Thank you for the answers so far but could you maybe give me a code example for the part where the number gets replaced by the picture? Thank you!

You can make use of the UITableViewDelegate methods for editing such as tableView:willBeginEditingRowAtIndexPath: to perform your changes. Use cellForRowAtIndexPath: to get the UITableViewCell object.

You can use a custom cell here and do all those works. Here you can use the same cell and add a subview to that cell where you want that change to happen. Later depending on the state i.e; isEditing = True/ false you can display what you want.

Related

UITableView trigger when cell is reused

I'm having some issues with reusable cells in a UITableView. I have several types of cells, that I declare in the constructor.
My issue is that I have one particular type of cell that contains a UITextView and I have an issue when I scroll the table, the text within is lost. I need to save this text to the models that accompany the cells and then put the text back when the cell is used again.
How do I know that the cell is being moved away from? I have other types of cells, so I need a way to invoke some code to do the saving part on the scroll of the UITableView.
I hope that makes sense, if more is required, let me know.
Thanks.
Just save the text once it is changed to the model, check if any text is present and use that in tableView(_:cellForRowAt:)
For more help you will have to show us your code.
You can inherit UITextViewDelegate and in the textViewDidEndEditing(_:) check if the text view is edited, then you will be able to store the text in a variable or somewhere else and restore it whenever you are about to show that cell again.
If there is more than one text view, you might want to set an accessibility identifier for each kind, so you will find out which one did end editing.

Only one cell could get user input - TableView

I have three cells in my tableview which is standard tableview not custom cell. However, I would like the last cell to be editable, in other words I want that cell to get user input, something like textfield, but other cells just static and not editable.
I know how to make custom cell and make it work, but before I dive into that option I would like to know is there a tweak that I could use.
I wonder it is possible without making all tableview in custom cell?
You can use UITableViewHeaderFooterView instead of last cell. I think it is better way to add some UI into TableView.
You just need to override a method which is here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html#//apple_ref/doc/uid/TP40006942-CH3-SW22
There is a simple example here:
http://www.ioscreator.com/tutorials/customizing-headers-footers-table-view-ios7
I hope that is helpful for you.

How to Use Custom UIButton in UITableViewCell?

I am trying to figure out the best way to apply UIButtons in tableViewCell, I've used tag method. like cell.customButton.tag = indexPath.row, then giving it a target.
But it din't work fine for me if the tableViewCell has may things to show with the same button in all the cells.
There are two options to show the title of the button , just like if we follow a user and unfollow, so after deleting or clicking on any button , it changes the title of some other button also , So, tag method isn't a good option I guess.. Any help would be appreciated.. Thanks!
Using a protocol in a custom table view cell class is what i would suggest:
check out this gitHub commit or download zip for the full project
Adding a Subclass and protocol to a UITableViewCell
I shall have this in the form of an answer later. let me know if you have any questions about the project

UICollectionView selection does not last

I have a UICollectionView I use like a tool selection container. You have many tools (the cells), when you select one, the former selected is deselected, and so on... You can only have one tool selected at a time.
The problem is that I can't manage to have the cells selected. When I tap the cell, the collectionView:didSelectItemAtIndexPath: is called. I then reload the selected cell to change it's appearance (I change the alpha of the image) by using the [collectionView reloadItemsAtIndexPaths:#[indexPath]].
Well that reloads the cell ok, except one damn thing: in the collectionView:cellForItemAtIndexPath: the cell never get the selected property set to YES! So I can never change the alphabecause I never know when I must draw a selected cell or not.
Worse: [collectionView indexPathsForSelectedItems] is always empty!!!
I don't even mention the collectionView:didDeselectItemAtIndexPath: that is never called...
Well, if someone can help me understand what is going on, thanks in advance...
When you call reloadItemsAtIndexPaths: the collection view discards those cells and creates new ones, therefor discarding the selected state of the cells.
I'd suggest a couple of different options:
1.) In collectionView:didSelectItemAtIndexPath: call cellForItemAtIndexPath: to get a reference to the selected cell and update it's appearance there.
2.) (My Favorite) Use a custom subclass of UICollectionViewCell if you're not already, and override the method setSelected:. There you'll be notified when the cell is selected and you can update the appearance from within the subclass.
With regards to selecting multiple cell at once, you should try the allowsMultipleSelection property [myCollectionView setAllowsMultipleSelection:YES] The docs for that are here: https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionView_class/Reference/Reference.html#//apple_ref/occ/instp/UICollectionView/allowsMultipleSelection
Otherwise, #daltonclaybrook's answer is sufficient.

How to disable: Drag across UITableViewCell selects it

When you drag over a UITableViewCell in a TableView, the cell gets highlighted ("selected"), but didSelectRow... is not called. I wish to disable that selection. How would I do that? Note that setting the selectedStyle for a cell to selectedStyleNone, or something like that, is not what I want. I really want the OS not to select it.
Thanks in advance,
I think the property your searching for is BOOL allowsSelection declared in UITableView. By passing "no" the tableViewCell is not selected when the user touches it. The same is true for BOOL allowsSelectionDuringEditing.
I hope that fixes your problem ;)

Resources