I want to enter edit mode when user selects a cell (if not in edit mode) and exit edit mode when user selects a selected cell (and is in edit mode, obviously). I have everything working except for this slight problem: When the table view is not in edit mode and the user selects a cell, the cell highlights but then immediately "deselects", ie. the selected background flashes and then disappears. I have confirmed that immediately after the call to setEditing:animated: the tableview's selected cell is nil. I want it to maintain its selected cell after the call to setEditing:animated: Unfortunately, even calling selectRow:animated:scrollPosition: after setEditing:animated: doesn't properly select the cell.
Check the table view's editing property. Select Single selection During editing
Related
Is it possible to make changes to a particular UITableViewCell? For example, change the text in one cell of a table view with a button click?
It's possible, but you should not do that.
As you said in your comment, you can ask the table view for a cell and then make changes to that cell, but don't do that.
You should do what HHumorous said, and change your data model, then tell the table view to reload the affected cell.
If you simply change the appearance of the cell, then when the user scrolls that cell off-screen and then back on-screen the changes will be lost.
I have a table view with several rows. I have enabled multiple selections in edit mode. When I toggle edit mode, I initially select all rows programmatically. Everything works fine except for re-selecting a row that was deselected by tapping on the empty circle where the checkmark was.
Table View Configuration:
Sample Cells, one has been deselected:
The interesting thing is that I can tap on the checkmark to deselect a row (didDeselectRowAtIndexPath is called), but immediately tapping on the same spot again will not call didSelectRowAtIndexPath. I have to tap on the main part of the cell. Naturally, this is not a good user experience.
Here is an overlay showing the areas that respond to taps highlighted in green.
I have been unable to find any events that are fired when tapping on the edit control of a deselected row. I have no code inside didSelectRowAtIndexPath or didDeselectRowAtIndexPath and I am just relying on the list of selected cells that the tableview maintains when the edit mode is toggled off. Any help isolating this issue would be greatly appreciated.
The problem ended up being that I was setting a backgroundView on my custom table cell and that was preventing the touches from getting to the right target.
I have some customised UITableViewCells which contain a UITextView and a set of buttons. The buttons in the cell should be visible only when the user tries to edit the text view in the corresponding cell.
So, if the user attempts to edit the textview in cell1, then the set of buttons should be visible below the textview in cell1 and the height of cell1 should also be increased. Now, if the user attempts to edit the textview in cell2, then the set of buttons should be visible below the textview in cell2 and the height of cell2 should also be increased, whereas the buttons in cell1 should get removed and cell size needs to be calculated accordingly.
For this I tried to reload the table view cells from textViewDidBeginEditing:. This is reloading the cells properly and shows/hides the buttons properly in the required cells, but does not allow proper editing of text view. When the user tries to edit with the textview, the tableview reload methods are invoked constantly and not allowing the keyboard to stand for editing.
Is it right to handle reloading from textViewDidBeginEditing: in first place ? is there some better way to do this ? please help.
First I would suggest that do not reload the entire TableView each time. Instead use the
reloadRowsAtIndexPaths
method to load only the cell in which you want modifications.
Next, to solve your issue regarding the textView, you could do something like this, declare a class property of bool type, and set it to false. When you reload your cell for the first time, set it to true. Now in the textViewDidBegin editing method, check for this bool. If it is set to true, that means you already have loaded the cell and you do not need to load it again, so in this case do not call the reloadRows method. Else if it is false, reload the rows and set this bool to true.
Now in the textViewDidEndEditing delegate method, set this bool to false again so that when a user taps on another textView in some other row, it is reloaded properly.
This logic may not be perfect, you may require some tweaking. But it will get the job done
Explicitly make the textfield as firstResponder
if buttonsDisplayed == NO {
reload cell
}
if textFieldIsFirstResponder == NO {
[textField becomeFirstResponder];
}
I'd like to display an accessoryType in a UITableViewCell in which an UITableViewRowActionButton has been pressed. The accessoryType should also be displayed if the app relaunches. So I think I have to store something. Does someone have an idea how to do this?
You need to learn how table views work. They have a data source that configures cells based on the saved state of the data model.
What you should do is set up your data model to save the fact that the user has pressed your cell button. Save that information to a file, and load it when the app launches.
Set up your cellForRowAtIndexPath to look at the saved information for that row and display an accessory in those cells where your saved information shows that the user has tapped your row action button.
In the IBAction method for your row action button, you can simply set the "the user has clicked the row action button for this row" flag and tell the table view to reload that indexPath. Your cellForRowAtIndexPath will then reload the cell with the accessory .
I have implemented a table view with multiple threads. Currently when a user taps on a cell a different thread starts downlading the content in the background and the user is free to choose a different cell before the content is loaded.
Currently the app will show the content of the first tapped cell and then immediately switch to the content of the 2nd cell.
My question is if a user selects a cell and then before the app can switch to the detailview they select another cell, how do I only show the contents of the second cell and forget about the 1st cell?
You have different ways to do this; speaking generally you'd have a callback of your asyncronous computation. In that callback, simply look at the last indexPath selected and match whether or not it's the same indexPath who triggered that computation.