Any suggestions regarding factoring a massive view controller, with multiple cell types, cell sizes. Because each cell has its own delegates, the view controller becomes super confusing when navigating through the file.
Or is this the standard approach to for multiple cell types? How would you go about building multiple with multiple sections & cells. Much thanks!
//Rows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 && sectionArray[0].isExpanded {
return sectionArray.count
} else if section == 0 && sectionArray[0].isExpanded == false {
return sectionArray[0].section.count - 1
}
if section == 1 {
return 3
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 && indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteIconCell", for: indexPath) as! CreateFavoriteIconCell
cell.delegate = self
return cell
}
if indexPath.section == 1 {
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoritePhotoCell", for: indexPath) as! CreateFavoritePhotoCell
cell.delegate = self
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteLocationCell", for: indexPath) as! CreateFavoriteLocationCell
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteDescriptionCell", for: indexPath) as! CreateFavoriteDescriptionCell
return cell
default:
return tableView.cellForRow(at: indexPath)!
}
}
return tableView.cellForRow(at: indexPath)!
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
switch indexPath.row {
case 0:
tableView.rowHeight = 58
default:
tableView.rowHeight = 0
}
}
if indexPath.section == 1 {
switch indexPath.row {
case 0:
tableView.rowHeight = 120
case 1:
tableView.rowHeight = 60
case 2:
tableView.rowHeight = 160
default:
tableView.rowHeight = 0
}
}
return tableView.rowHeight
}