I want to present different byte arrays in up to 25 tableviews. But currently it is only being presented in the first tableview.
I currently have a UICollectionviewcontroller, with a menubar with up to 25 collectionviewcells that I can select to go to that cell. Each cell displays another CollectionViewCell, with a tableview inside it.
I am sending byte arrays to be displayed in the tableview.
After a given time(When no data is received after 2 seconds with timer) OR "All data received this session byte array" there will be a new cell in the menubar, with a new uicollectionviewcell underneath the menubar with a new tableview insde. Which is gonna be the new session of byte arrays.
I dont know how to make this to work. Ive seen a lot of examples with people using 5 reuseable cells for 5 tableviews
table1.tag = 1 table2.tag = 2 tablex.tag = x table1.dataSource = self table1.delegate = self tablex.delegate = self etc....
But in my case I dont know how many cells there will be with tableviews. Sometimes it might be 5.. or 10 or 25, or even just 1. It all depends on the data.
Even if it was 25 everytime, and I would use a switch statement for 25 cases with different reusablecells, and datasource and delegate set to self in each. Which in my opinion is not good code.
Anyways guys I hope you can help me with a solution how I do this more clean! Im also not so experienced in programming.. Please ask if there is anything!
EDIT
class NewReceiveViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, {
viewDidLoad:
..
collectionView.register(ReceivedCell.self, forCellWithReuseIdentifier: "cell")
MenuBar: With a timer on 2 seconds, it adds a new cell to menubar, right now just using random colors to see its working
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath as IndexPath) as! MenuCell cell.backgroundColor = self.colors[indexPath.item] cell.tintColor = UIColor.rgb(red: 91, green: 14, blue: 13) return cell
Collectionview under menubar:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ReceivedCell cell.tableView.reloadData() cell.backgroundColor = UIColor.lightGray return cell
Tableview:
extension ReceivedCell: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return recievedArrays.count //array.count } func tableView(_ tableView: UITableView, cellForRowAt IndexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.value1 , reuseIdentifier: tableViewCell) //...code for labels return cell
This data transfer goes very very fast. In the beginning the data will be presented in the first tableview, and after 2 seconds, it will make a new tableview in the next CollectionViewCell cell, and I want to present the data there, and then 2 seconds next, and so on!