Change view in all collection view cells - ios

I have a collection view where each cell has a video (played through AVPlayer) and a red circle. When a button in the view controller is clicked, the color of all cell's circles should be changed to blue, and then if clicked again, changes it back to red.
So what I need to be able to do is: when the button is clicked in the controller view, change the circle view in all cells, visible or not. The reason I say visible or not is because I only show one cell on the screen at a time. The user swipes to go to the next cell.
I have already tried using reloadData() to update all cell's circles when the button is clicked, however, the problem I discovered is that the video resets back to the beginning (and I need it not to do that, not just for the visible cell, but for all cells).
What are my other options?

When a button in the view controller is tapped you would need to change the data/collection/array of data that you are loading in your collection view. In order to achieve the result in (for example didSelectItemAtIndexPath:(NSIndexPath *)indexPath) you should change the data model for that specific cell/collection item. You can add for instance property isSelected for your collection view data model(s).
In your case, calling reload data calls all the UICollectionViewDelegate & UICollectionViewDataSourcemethods, however since you have not change the data using, the result/UI returns to the initial state.

Related

What is the better way to implement MapView with multiple BottomViews or PullUpControllers?

I am a beginner in developing iOS applications. Working in an application, where I am making all views programmatically.
I want to display a Map along with different bottom views. When first time the view is loaded, it displays Map along with first bottom view. When user performs an action, it displays the second bottom view but with the same Map View.
So in a nutshell I need to keep the same Map view but display several bottom view based on user action. I am looking for a better way to display bottom view based on user action and if user click on back button, it should return to last-displayed bottom view.
I tried to apply NavigationController on the bottom view controller (which is a child controller to Map View Controller) but it displays the child view in the entire windows instead of displaying in the bottom.
I also thought of registering bottom views to an event and show/hide bottom view based on what kind of event occurred. But here I also want to keep track of last event so when user clicks on back button it should display the last view. As this is very initial state so don't know if it's a good idea or not.
use a collection view with paging enabled and width of each cell equal to the screen width and scroll to next cell based on user action.

Load table view cell with edit options showing by default at initial launch of table view

I want to show table view cell showing edit options by default without applying swipe at the initial launch of the table view. I have tried setting tableView.edit actions property to true but it is not swiping the cell. It is only showing a delete button with action set to swipe. I want to perform swipe automatically at viewDidLoad()
Actually, there is no way to do that. Apple doesn't provide an edit mode on the UITableViewCell. Whereas UITableView has it.
Maybe there is a workaround for the problem you are trying to solve.
In one of the problems, I had where we wanted to let our users know that the table view cell has actions on top of them. What we did was added a custom view on top of the cell and did some animations to show the user actions.

Reusing a view for different purposes

I have a view which is used for updating the content of a table cell and adding new cells to a table.
Updating the content of a table cell can be achieved by touching a cell. In this case the view will be instantiated programmatically and the data of the cell will be sent to the view. Adding new cells to the table can be achieved by clicking on a button which will show the view as a segue without data.
The navigation bar of the view contains a save button which will update the data of the cell or add a new cell.
I thought about setting a boolean value in the view to detect if the purpose is updating or adding a cell but I don’t think that this would be the right way. What is the best solution for this problem?

Xcode + Swift: Showing view on top of another

When my app performs a certain segue, I want the new view to be shown on top of the previous view, like a background. How do I do this?
If this is not possible, is there any way I could programmatically take a screenshot of the previous screen to use as a background for the new screen?
There's a method on UIView, snapshotViewAfterScreenUpdates: than will give you a composite view of the current screen. You could use that for your background.
You might look into custom view transitions to do what you're after though.
Instead of a segue to a different view controller, why not just add the new view to the current controller, place it so that it appears above the first view and then set it as hidden.
When the user taps the action that would trigger the segue (a tableview cell for instance), then instead to triggering the segue, just mark the second view as visible and populate it's content with what you need to display.
With a clear background on the second view, it will overlay the original view. Then you can just add some control to hide it once they're through.

Navigate between cells from a detailed view with a next and back buttons

i have a table view filled with landmarks that leads to a detailed view and i want to know how can i add a next and back button on my detailedViewController to navigate between the landmarks that i have on my tableview with out having to go back to the tableview
thanks
Wrap your detailView in a UIPageViewController.
Then the user can swipe left and right to receive the next/previous landmark detail view, or use your buttons for navigation.
When you're instantiating the UIPVC, pass the array if landmarks used by your tableView so the UIPVC's delegate methods know how to select the next landmark.
Basically, every landmark will be a page that the user can navigate to.

Resources