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 .
Related
i have a tableview with form fields, and there is a row that use segue to call an UICollectionView, everything is works except that i can't keep the selected cells (the visual effect that i show when the cell is selected) after go back to the tableview.
I mean, i selected my UICollectionView cells, after that i go back to the form, but if i need to again to my UICollectionView Cells, to deselect o select more cells before submit the data, once the UICollectionView appear my previous selection are there (i print the array, and i see the values) but i cant see the effect that i did for selected cells.
How i can keep the effect for selected cells if I'm going back to select again o deselect cells?
One thing to realize is that this is not going to happen by itself. When you segue back to the table view and the form fields, the UICollectionView is completely destroyed. The next time you show the collection view, it is a new and different collection view.
So, if you want to maintain a knowledge of what the selection was in the collection view, you are going to have to maintain it yourself, deliberately, storing it somewhere when you know that the collection view is being destroyed.
That way, the next time you show your collection view, even though that will be a completely new and different collection view, you can pass the knowledge of what the selection was to that collection view as you create and show it. The user will have the illusion of "returning" to the collection view, in the same state, but in fact you will have saved and restored its state.
It is then just a matter of reflecting the selected state in the collection view's display of its items. To do that, you need to configure your model so that when cellForItemAtIndexPath: is called, each cell looks selected if that item is supposed to be selected.
Every time you use segue to call an UICollectionView a new instance of UICollectionView is created and hence states of selected cells doesn't get restored.
I believe u must have taken an array of index paths of selected indexes to show the visual changes in the cell.
Make your tableView class as delegate of UICollectionView. Using its delegate methods return the selected index array to tableView class .And before pushing to UICollectionView send the same array of index paths back to the UICollectionView. Hope it helps.. Happy Coding.. :)
I am using a UICollectionView, in which one UICollectionViewCell covers the entire screen. Inside my UICollectionViewCell, I give people the opportunity to add text (UILabel), images (UIImageView) and color (UIColor). Now when the user navigates to the next cell i want the color, labels and image views to be displayed exactly as they were added on the previous cell. The users also have the option to pinch and pan the labels and images. In short, how can i pass on data from one cell to another?
I see several ways how to do this depending on your realization:
use global properties/ivars to store the selected data from user input.
In either case you probably handle UITextFiledDelegate methods in your controller or extract the cell by indexPath and copy values from the current cell to the next one.
And when the user presses the "Continue" button you:
1) If you create all you collectionViewCells at once in cellForItemAtIndexPath, then you should only reload the necessary cell via - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths and set the values you have saved previously.
2) If you create cells but the next one is not ready (for instance you save the memory) - all almost the same - you add a new cell to the collectionView and read the data from your properties.
3) If you have not a "Continue" button or/and user can swipe the cell in every moment - so you can reload the cell in scrollViewDidScroll(or scrollViewWillBeginDragging) or extract the existent by indexPath and modify it without reloading.
I have a collection view that has cells that are being populated by a UIImagePickerController, that get pictures from my image library and inserts them into an Array and SQLite db. I have a button on the cell that i want to use to delete it. How do I delete the cell. Tags on the cell are available.
You can set the tag(indexPath.item) to button also in the same way as you did to your collection view cell. And in the action method you will get the button as sender. Access sender.tag to get the index path of the right item.
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
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];