IGListKit: get the currently visible cell index - ios

I am trying to use IGListKit (Link) in iOS to render custom collection view and table view, where I have a horizontal scrollview in a section controller. In this horizontal scrollview, I need to get the index of the currently visible cells.
I tried to use the displayDelegate in the section controller, but it seems to me that the following delegate method is triggered only once when the section controller is initially loaded:
func listAdapter(_ listAdapter: IGListAdapter, willDisplay sectionController: IGListSectionController, cell: UICollectionViewCell, at index: Int)
So I was wondering if there's a way in IGListKit to get the index of the currently visible cells. Thanks!

Did you checked IGListAdapter's Visible Objects and Visible SectionController functions?
https://instagram.github.io/IGListKit/Classes/IGListAdapter.html#/c:objc(cs)IGListAdapter(im)visibleSectionControllers

self.section provides the index of currently visible cell.

Related

UICollectionView: how to scroll to supplementary element instead of cell?

So here is my setup:
UICollectionView configured with UICollectionLayoutListConfiguration
appearance is UICollectionLayoutListAppearancePlain
headerMode is UICollectionLayoutListHeaderModeSupplementary
Using UICollectionViewListCell with content configuration
Implementing collectionView:viewForSupplementaryElementOfKind:atIndexPath: to return custom section header
Implementing indexTitlesForCollectionView: to return index titles representing the sections (e.g. "A", "B", "C")
Implementing collectionView:indexPathForIndexTitle:atIndex: to return the index path of the first cell in given section.
Now, when user taps on any index title, the collection view scrolls and positions the first cell of that section at the top. However, the header section (which is sticky) is now overlapping part of the cell.
Any suggestion on how to fix this?
I guess that a new delegate method, such as collectionView:supplementaryElementIndexPathForIndexTitle:atIndex: would probably target this use case (as the collection view would scroll to a section header rather than to a cell).

Swift Button That Outputs UICollectionView Cells One by One?

I made a UICollectionView, and everything is working. It makes 100 cells that I can scroll through in simulator with no problem.
However, rather than seeing all the cells at once, I want the cells to be released one by one whenever that red button is pressed.
I am confused because I noticed in the storyboard, it hard codes the number of cells it has on the screen at once. Is there any way to get around this?
Thank you!
This is what the UI looks like in storyboard.
This is the code I used to make it. It's basic, and just says to fill the text box of the cell with a string from the array.
Your question is garbled.
A collection view has a delegate and a data source. The data source responds to messages in the UICollectionViewDataSource protocol. That protocol lets the collection view ask how many sections it has, and how many rows in each section, as well as asking for the cells from those sections and rows.
There are also methods that let you tell the table view that you want to add more cells. Take a look at the method insertItems(at:). That lets you provide an array of indexPaths, which tells the table view that you have added new entries.
You could certainly write a button action method that added one or more entries to your data model and then used the insertItems(at:) method to notify the collection view that it had new entries. If there was room in the content view of the collection view to display additional cells it would then call the data source and ask for new cells at those index paths.
Sounds like you just need to keep track of how many items you want displayed (which will increase the more that button is pressed) and use that in your UICollectionViewDataSource method. Something like:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return min(myRunningItemCount, maximumNumberOfItems) //assuming there's a maximum
}
Then you just need to call reloadData on the collection view whenever that number changes.

Detect section of UICollectionViewCell

I have got UICollectionView with custom layout, so there is a row of items, that are scrolling with paging. Also there is a multiple sections, so the final view is like an App Store example of final view is as below,
Problem is, to place in each section footer a page control, that will detect current page of section. I don't know how to detect in witch section scroll view offset was changed. Will appreciate any help or another solutions!
You can get the section and row in which the collection view was selected using the following delegate method.
// Swift
func collectionView(_ collectionView: UICollectionView,
didSelectItemAtIndexPath indexPath: NSIndexPath)
// Obj-C
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
Here, this method is invoked on the delegate only when a cell is selected. It returns indexPath.
indexPath contains two property you are asking for right now.
indexPath.row - Gives the item currently selected item index in section.
indexPath.section - Gives the current section being used in the collectionView
Note: Counting Starts from 0, not 1.
So if I selected "ComboCritters" ( Look image above), I would get 0 for indexPath.section referring to the "New Games we love! " and, 2 for indexPath.row saying the 3rd item is selected.
And, that's how you get the selected section in your app.
Kind Regards,
Suman Adhikari
You can't have the three sections highlighted in red in your diagram as separate sections in the same collection view if you want them to independently scroll. Scrolling happens to the entire collection view, not to one section of it, unless you have a very complicated layout subclass.
It would be far simpler to have three collection views, one for each section.

How can I parse image from table cell inside table view to detail view in iOS?

I have an image inside my tableview cell.
What I want to do is when I click on that cell I want to parse both text & image to detail view.
I can do for text but I can't get the point about image.
So, simply my question is how can I parse image inside tableview cell to detail view in iOS.
Thanks
You can use it as the same way you're using it. Use indexPath to specify the row you wanna manipulate.
Here's how you do it. implement UITableViewDelegate in your ViewController, and implement the following method.
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
The short answer, you access the image the same way that you set it. In the case of the standard UITableViewCell, it is the imageView property that you used.
For these API type questions though, there is no better place to start, than the documentation

UITableView inside custom UICollectionView

As the title says, i'm trying to put one UITableView inside a custom UICollectionViewCell, i made it so it's perfectly displayed, but now i need the touches inside the Cell that contains the Table to call the didSelectRowForIndexPath method.
I have a .xib for this custom UICollectionViewCell, inside it i have the UITableView, and i have it's delegate and datasource correctly set.
Now, if i run this, the CollectionView cells are loaded with their proper data (this is, each cell with a table containing the proper rows), but if i try to select one row from one table, the CollectionViewCell is selected instead of the TableViewCell (this is expected, but not what i need).
I'd like to know if is there a way for the TableView row to get selected, even if it's inside a CollectionView cell.
Thank you and sorry for my english.

Resources