How can I place a view between cells in collectionView? - ios

I want to place a view between cells in a collectionView. Like an ad. to be added dynamically after they see the first 3 cells. Is there a method to do that?

If you could figure out a way to do that you still shouldn't. A collection view owns the area it draws in. It's in charge of placing cells where they belong within it's content view, and you are supposed to keep out.
That said, collection views are extremely flexible and you could design your collection view to display a set of "normal" cells, an ad cell, and then more normal cells. If your ad cells are different sizes or need to be spaced differently than your normal cells then you might have to create a custom collection view layout.

No, you can't. But you can add a UICollectionViewCell which will contain advertisements or something else you want to be added. It is really simple. Just create two prototype cell. First cell will contain your data, second one will contain some extra data.

Related

UITableView cells on the same row

as I say in the title, I'd like to display two or more cells on the same row. I have every cell with a UILabel inside. The labels can have changing width depending on user's input. I'd like to fill a row with many labels as I can. Can someone give me some advice on how to do it? Thanks.
Short answer: You can't. Slightly longer answer: Use a collection view.
Table views are designed to show a single column of cells.
You can't make a table view contain multiple cells in a row.
You could probably create a view controller that had side-by-side table views inside it, but it would be awkward and hard to use, and the table views would scroll independently of each other.
If you want multiple cells on the same row, you want a collection view. A collection view is similar to, but more flexible than, a table view.
I would consider using a horizontal UIStackView to achieve what you're trying to do. Depends on how dynamic and changeable you need it to be.

How to achieve a (almost) full view uitableview that can scroll past the last cell and show further elements in iOS

I have attached the below image because it describes my problem better than words:
So basically, I need the Title/Subtitles part at the top to always be static, after that a dynamic UITableView which will have a lot of cells (mostly will fill the rest of the screen), and then after that a few additional elements such as a Map View and etc.
I'm using storyboards/xibs for this so it was also an issue of how to constraint everything in the designer properly. Would a stack or scroll view be appropriate for this?
I think you can take two paths to achieve this.
The first is to create a custom cell containing the map and another containing the "Paragraph of text" thing.
Then you only need to push the cells at the end of the original data source.
Keep in mind that you need to add this cells to the RowsInSection function.
The other way is add a custom footer view to the tableView.
You can create a custom UIView containing the map an other info and then tell the table to take the custom view as footer:
tableView.tableFooterView = customView

iOS StackView or CollectionView

I have to make a grid with a specific architecture.
I don't know if I have to use a stackView with views? Or a collectionView with cell?
Let's see my image :
Green cells will be repeated infinite times.
Thanks for your help!!
The easiest and best way do make this is collection view, Also in collection views cells(items) are reused, so you don't need to release them after they have disappeared.
It depends on the number of grid cells. If the number of cells is 2~4, it's OK to use stackView.
But
Green cells will be repeated infinite times.
So, you should use collection view. Collection view is suitable for displaying repeating layouts like your image or calendar app on iOS.
And offscreen collection view cell(table view cell also) is reusable, so you only create cells enough to fill the screen and a little more.
See Table View Cell Reuse Explanation

How to make cell doesn't scroll along with other cell?

I am making an app that use table View Controller and static cell.
I want to make first cell don't scrolling while other can. This is a picture of what i am talking about.(Sorry for my bad English)
For example as in this picture, I want to make 9gag tab stay when scroll. If you play instragram you will see that when you scrolling the name of user will stay until you scroll into another one. However I want it to stay not changing when it encounter second cell.
Any suggestion?
Using UITableViewController would not help here. You can use these steps to get what you want:
1. Create a UIViewController.
2. Add UITableView as its subview.
3. Add another UIView as UIViewController's view's subview.
4. Using auto layout constraints, you can put UIView above UITableView
This way, you will get a sticky view at the top.
Ok, not exactly sure what you're after but i'll take a stab.
Firstly, if you want the section to remain in place until a new section of items is present, you just need have a look at sections. This is an automatic feature. You may not see it occur until you have plenty of items in the sections.
UITableView With Multiple Sections
There's plenty of stuff about it & not too hard to implement.
My other guess of what you want:
If you want it to remain static regardless of anything, perhaps you could just create a view and place it above the table view. why does it need to be a part of it if it doesn't change?

iOS Collection View Cells: Strong references during reuse / prevent cell reuse?

Question: What happens to references to a collection view cell when it is scrolled offscreen and reused? All my attempts to supply cells without using "dequeue" have failed. Is there a way to tag a cell as non-reusable, so the collection will keep it around? I want to tell the collection "Hey, don't reuse this cell yet!".
Long story: I have a collection view where each cell has a collection view in it. I am using a custom layout (https://github.com/lxcid/LXReorderableCollectionViewFlowLayout) on the sub-collection views to enable dragging and reordering of cells, but I want to extend this to allow dragging cells from one collection view into another. I have it working, except that if a cell is dragged from a collection view that is then scrolled offscreen during the drag, it breaks because the layout handling the gesture, and its collection view, have been reused. The cell with the collection view and reorder-able layout is still doing work, and I need it to not get reused.
Thanks for sharing the long story. It helps to see what you're trying to do. I can understand your approach and can see why you might initially think this is a good logical approach.
However, I'll try to convince you to try to use another approach. The common approach is to take a snapshot of the view during the drag, then add it to the superview and move it around with the drag from one collection to another. Let me know if this approach makes conceptual sense.

Resources