iPhone clearing TableView cells so they are fresh - ios

I want a "New Session" button I've created to clear the changes made to my TableView's text and accessory icon.
For instance, I currently have my program coded to add a "UITableViewCellAccessoryCheckmark" for each cell when it's pressed. That cell's text is also turned green.
I would like to have a button that resets the entire TableView, so all text returns to default color, and all accessories are cleared.
How would I do this?

Pretty easy. First update or reset your data model as needed, clearing any flags, reloading the data from wherever you got it from, etc. The call [yourTableView reloadData];

Related

Is it possible to change attribute of individual UITableViewCell?

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.

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.

iOS: Make content (text) in table view cell editable, but only in edit mode

I know this has been asked a lot of times but theres so much different information and different cases, I just don't understand where to begin and cannot get it working in my app.
In my app I have a table view and I'm using a NSFetchedResultsController. In normal mode, the table cells shouldn't be editable but instead each click should be a segue to a new viewcontroller (which works). In edit mode however I want that if you click on the cell, that you edit the text and this gets automatically stored to the database. And here I don't have a clue.
I want it as simple as possible. What I've read so far I guess I have to subclass UITableViewCell and a TextField. Here's already my first question: In each post about this, the TextField is init with a Rect, however how do I know the exact width and height of my cells?
And do I add this cell directly in the cellForRowAtIndexPath? Or only if the mode gets changed to edit? And some posts suggest you have to be the delegate for UITextField, but why?
And is there some sample code for about exact the problem I have? I wasn't able to find it...

UITableView reusable cell or not

I'm developing an app that represents a huge amount of data using UITableView with a custom UITableViewCell.
When the tableView is set to editing mode, it supports multiple selection for further usage of the selected set of data.
Using -tableView:didSelectRowAtIndexPath: and didDeselect I'm changing the rows UIImageViews image to a little tick and storing the selection into an array. When selecting a cell it gets light blue background (iOS standard).
When I'm now scrolling down and up again, the cells background is still light blue but the image is reset to default and the cells isSelected property is NO. Selecting it again invokes the -tableView:didSelectRowAtIndexPath: method.
After a while debugging it turned out that the reusable identifier was wrong. But as I corrected it, scrolling down repeated the same 12 cells over and over again. And the isSelected property is still reset to NO.
How can I maintain selected rows while scrolling the tableView?! And: Why is the cell blue highlighted (or marked as selected) but the isSelected property gets reset to No?
Thanks for help, with kind regards, Julian
Don't use the cell to hold persistent controller state. Instead keep an NSArray and add the NSIndexPath of each selected cell to your array (and remove them if/when the user deselects a cell).
Then in cellForRowAtIndexPath: just make sure you configure the cell correctly based upon whether or not its index-path is in your array of selected cells.

How to refresh a UITableView in iphone?

I have a UI table view loading data from network. If the user move the finger on one cell, one button will be displayed, just like iPhone style delete button. If the user click this button, the value of one label in the cell will be changed accordingly. However, I didn't find any way to make table view to re-draw this cell, except for reload the whole table. I don't want to use reload data method, because I just need change the value in one cell instead of the whole table. Any suggestion on this?
Take a look at the method
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
Calling this method will result in your table view's data source asking its delegate for information about that cell.
For future reference, I found this very easily by checking the documentation on UITableView. I suggest you do that in the future before posting here.

Resources