selection and deselection in UICollectionView swift 2 - ios

I'm beginner in using Xcode7 and swift2. I used them to create collection view inside table cell.
I followed the tutorial in this link: https://www.thorntech.com/2015/08/want-your-swift-app-to-scroll-in-two-directions-like-netflix-heres-how/
Everything works fine, expect the selection when I selected one cell form the collection and scroll horizontally to select a different one the following happen:
1-the first selected one does not deselected.
2- the second one get selected,
now I have two selected cells and the app crashed.
I want the user to select one cell only from the collection, so I used didselect, and deselect method, but still not working as expected.
Any guidance or resources to solve this issues are appreciated.

For your collectionView set .allowsMultipleSelection to false

Related

Move CollectionViewCell to another section

I have a UIViewController with a collectionView inside it. The layout may seem confusing but I am making use of horizontal scrolling UICollectionViewCells, presented in 3 sections.
The main collection view is made up of 3 sections. I access 3 different UICollectionViewCell classes for each section becuase it is fetching different data for each one. Once the data is fetched, it dequeues another Cell class, which is the same one accessed for all the sections.
There are 2 buttons in each cell. When I press the button, a value changes within the database. When I re-run the program, the cell in which the button was pressed has moved to its corresponding section that it should be in as per the change. However, I want to achieve this as soon as I press the button. How can I move the cell from one section to another, baring in mind that they the cells presented are inside a collectionview cell making up the sections, which is then inside a greater UICollectionView.?
I've tried researching how to do this but no luck, and everyone seems to be using a drag and drop method which seems too complicated for what I am trying to achieve. Would appreciate any help.
Thanks
The approach I followed to achieve the above situation is using a custom Delegation when cell is removing from collectionviews. A container CollectionView has two sections with 2 different cells containing two different Horizontal UICollectionViews. These two collectionview's cells have UIButtons. When tap on one collectionView's button, that particular cell is removed, custom Delegate method calls and another CollectionView's cell is populated. This is the link of the project I have created for this particular scenario. For better understanding, here is a GIF for demonstration.

How to display detailed row in TableView#2 when row in TableView #1 is tapped? (Swift - iOS)

I am kinda stuck in my iPhone app project (Swift, iOS, Xcode 7, using a StoryBoard), and I am hoping someone would be kind enough to give me a helping hand.
I am trying to link two Tableviews in such a way that when the user (me!) taps any row (each row = day of the week) in the 1st TableView it takes him to a more detailed row in the 2nd TableView; in a row, the user would enter info for 4 items, and in that 2nd TableView, the user would be able to add as many similar rows as he wishes to again enter different info for the 4 items such Time, Event, Place etc.
When I tried to create that 2nd TableView (dragged ViewController into StoryBoard, inserted TableView object, added 1 dynamic cell), I simply was unable to link it with the 1st TableView...
VoilĂ ... Any help will be hugely appreciated as I am new to that environment. Thanks in anticipation.
Cheers,
Laroms
It seems like you just need to link a NavigationController from one TableView to the second TableView. Make sure you right-click and drag the action to the appropriate methods.

how to scroll the collection view in uitableview in ios9.0?

I am facing problem only in the IOS 9.0 earlier versions i can able to scroll them easy and also i didnt get any problem like this.
this is my uitableview.I am loading many collectionview in this tableview but when i am trying to select the collectiovew cell in that time i cant able to select and also i cant able to scroll them horizontally.When i am trying to select the cell in that time the entice tableview cell is going to select.please help me how to select the collection view cell and also how to call the target method.
Please help me to resolve this problem.
I am waiting for your suggestions.
to calling the collectioncell i am using the protocol methods.
those are also not reflecting.
Sorry, but I am not sure if I understand your question.
I assume you have in every table view cell a collection view with a horizontal flow layout. If so, every table view cells would show multiple collection view cells that should be scrolled horizontally.
I would check:
Is user interaction enabled for your collection view cell? Otherwise
a tap would handled by the table view cell.
Is scrolling enabled in your collection view?
Did you set the delegate for the collection view? Otherwise no
target method would be called.

UICollectionView showing selected cells

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.. :)

adding a control to a custom cell view

I am getting really frustrated trying to solve this problem i tried implementing it in many many ways but no solution. I have a UIStepper in a custom cell and i want to change a value on the cell. Everything works fine expect when i scroll around the tableView the values from the UIStepper changes from one cell to another. Please help here are my screen shoots.
Link to tableview implementation and link to cell implementation
You are trying to store the stepper value inside each individual cell. That's not going to work because cells are reused; the cell that you now see in row 2 may reappear in row 20 when the user scrolls.
That is why you must store the value for the stepper in the model (your data) on a row-by-row basis, so that you can set it freshly and correctly for that row every single time cellForRowAtIndexPath: is called.
This, in turn, means that as the user steps the stepper, its valueChanged is going to need to talk to the table view data source so that the model can be updated ("the stepper value for row 5 has just been changed to 3") and maintained in the model.

Resources