collectionView and arrays (3 part question)

I have a collectionview of UILabels. when you tap a cell it should display its detail onto a pop up modal view.

  1. How do you display it onto that modal view in the same View controller?

2a. How can you cycle (loop) a group of arrays via UILabel forward and backwards in cells?

2b. How do you filter the arrays so that it always shows with a specific cell? (eg: Cell 2 will always have "D, E, F" when scrolling through)

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

		return totalSquares.count

	}

	func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

		let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calCell", for: indexPath) as! CalendarCell

		cell.dayOfMonth.text = totalSquares[indexPath.item]

		return cell

	}
                    //    Cell 1       Cell 2      Cell 3
let myArray: String = [[" A, B, C"], ["D, E, F"], ["G, H, I"]] etc..

Answered by Claude31 in 692110022

How do you display it onto that modal view in the same View controller?

You could simply create a hidden view (with fields for holding the detail) in this viewController ; when you tap on cell, load the detail and unhide the view.

How can you cycle (loop) a group of arrays via UILabel forward and backward

What do you mean by via UILabel forward and backward ? I just don't understand.

How do you filter the arrays so that it always shows with a specific cell? (eg: Cell 2 will always have "D, E, F" when scrolling through)

If you set a tag on each cell (start from 0), then myArray[cell.tag] will give you what you need.

cell.dayOfMonth.text = totalSquares[indexPath.item]
cell.tag = indexPath.row
Accepted Answer

How do you display it onto that modal view in the same View controller?

You could simply create a hidden view (with fields for holding the detail) in this viewController ; when you tap on cell, load the detail and unhide the view.

How can you cycle (loop) a group of arrays via UILabel forward and backward

What do you mean by via UILabel forward and backward ? I just don't understand.

How do you filter the arrays so that it always shows with a specific cell? (eg: Cell 2 will always have "D, E, F" when scrolling through)

If you set a tag on each cell (start from 0), then myArray[cell.tag] will give you what you need.

cell.dayOfMonth.text = totalSquares[indexPath.item]
cell.tag = indexPath.row

Okay got it, is it something like this? what do that block of code look like?

cell.detailTextLabel!.isHidden =  theSelectedRow != nil && theSelectedRow! == indexPath.item

By forward and backward, I mean by scrolling the views (of UILabels), the labels are populated with said arrays.

Accepted Answer

what do that block of code look like?

Block for doing what ?

By forward and backward, I mean by scrolling the views (of UILabels), the labels are populated with said [arrays.]

So there is always a single cell visible ? Could explain more in detail what you wnt to achiev, explain what is the set up ?

normally, using myArray[ indexPath.row ] to feed the cell lablel in

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

should be enough.

Sure, the set up is for a calendar. When the user taps a cell from the collectionview.. model view appears with date(cell) details. From there the user can also scroll the individual dates and their details.

collectionView and arrays (3 part question)
 
 
Q