Multi Section UITableView (swift) - ios

I try to make a multi section UITableView. I get it work if I only add two strings into my "overview" array. But when I try to call my class "Player" and "Comepetitions" I don't make it work. I have checked and both classes have elements.
//My player and Comepetitions class
var comepetition = [Comepetitions]() //Tävlingar
var players = [Player]()//Spelare
let sections = ["Tävlingar","Spelare"]
//here I want to replace my strings to my classes (player and Comepetitions class)
var overview = [[Player](),[Comepetitions]()] as [Any]
override func viewDidLoad() {
super.viewDidLoad()
print(overview)
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sections[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (overview[section] as AnyObject).count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ConconfirmCell", for: indexPath)
cell.textLabel?.text = overview[indexPath.section] as? String
cell.textLabel?.textColor = UIColor.white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 20.0)
return cell
}
//All Information how wants to follow the Segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//Segue for start a new game
if segue.identifier == "startNewGameSegue" {
let destVC=segue.destination as! GameViewController
destVC.competitions = comepetition as [Comepetitions]
destVC.players = players
}
}
}

This code works!
var comepetition = [Comepetitions]() //Tävlingar
var players = [Player]()//Spelare
let sections = ["Tävlingar","Spelare"]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.sections[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) {
return comepetition.count
} else {
return players.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ConconfirmCell", for: indexPath)
if (indexPath.section == 0) {
cell.textLabel?.text = comepetition[indexPath.row].comepetitionsOption
}else{
cell.textLabel?.text = players[indexPath.row].name
}
cell.textLabel?.textColor = UIColor.white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 20.0)
return cell
}
//All Information how wants to follow the Segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//Segue for start a new game
if segue.identifier == "startNewGameSegue" {
let destVC=segue.destination as! GameViewController
destVC.competitions = comepetition as [Comepetitions]
destVC.players = players
}
}
}

I think it's because of this line, it's optional and you should unwrap it but in the code you post there is no optional checking.
var comepetition = [Comepetitions?]()
And could you add the code that has problem because with code you post here the is no way to know witch is going to be section and witch is the items for that section.
Hope this will helps.

Related

How to change tableView numberOfRows and Cells based on which button is clicked in Swift iOS

I have two buttons in my user's profile page, one for the saved shop items and one for his reviews.
I want when the user clicks the saved button it would load his saved shop's items in the table view and when he clicks the reviews button it would load his reviews.
I'm struggling on how to figure out how to do this
Any help, please?
here is my code:
#IBOutlet weak var reviewsBtn: UIButton!
#IBOutlet weak var saveBtntab: UIButton!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(reviewsBtn.isSelected == true){
print("review selected")
return reviews.count
}
if(saveBtntab.isSelected == true){
print("saved selected")
return shops.count
}
return shops.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellFave", for: indexPath) as! FaveTableViewCell
let shops = self.shops[indexPath.row]
let reviews = self.reviews[indexPath.row]
// i want to do the same idea for the number of rows here.
}
#IBAction func reviewsTapped(_ sender: Any) {
reviewsBtn.isSelected = true
reviewsBtn.isEnabled = true
faveBtntab.isEnabled = false
faveBtntab.isSelected = false
}
#IBAction func savedTapped(_ sender: Any) {
faveBtntab.isSelected = true
faveBtntab.isEnabled = true
reviewsBtn.isEnabled = false
reviewsBtn.isSelected = false
}
First of all if there are only two states you can simplify numberOfRows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reviewsBtn.isSelected ? reviews.count : shops.count
}
In cellForRow do the same thing, display the items depending on reviewsBtn.isSelected
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellFave", for: indexPath) as! FaveTableViewCell
if reviewsBtn.isSelected {
let reviews = self.reviews[indexPath.row]
// assign review values to the UI
} else {
let shops = self.shops[indexPath.row]
// assign shop values to the UI
}
}
And don't forget to call reloadData when the state has changed.
You can create two different dataSource instances for clarity and separation like following -
class ShopsDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
var shops: [Shop] = []
var onShopSelected: ((_ shop: Shop) -> Void)?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return shops.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ShopTableViewCell", for: indexPath) as! ShopTableViewCell
let shop = self.shops[indexPath.row]
cell.populateDetails(shop: shop)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.onShopSelected?(shops[indexPath.row])
}
}
class ReviewsDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
var reviews: [Review] = []
var onReviewSelected: ((_ review: Review) -> Void)?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reviews.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ReviewTableViewCell", for: indexPath) as! ReviewTableViewCell
let review = self.reviews[indexPath.row]
cell.populateDetails(review: review)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.onReviewSelected?(reviews[indexPath.row])
}
}
class ViewController: UIViewController {
let shopsDataSource = ShopsDataSource()
let reviewsDataSource = ReviewsDataSource()
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(ShopTableViewCell.self, forCellReuseIdentifier: "ShopTableViewCell")
tableView.register(ReviewTableViewCell.self, forCellReuseIdentifier: "ReviewTableViewCell")
shopsDataSource.onShopSelected = { [weak self] (shop) in
self?.showDetailsScreen(shop: shop)
}
reviewsDataSource.onReviewSelected = { [weak self] (review) in
self?.showDetailsScreen(review: review)
}
}
#IBAction func shopsTapped(_ sender: Any) {
tableView.dataSource = shopsDataSource
tableView.delegate = shopsDataSource
tableView.reloadData()
}
#IBAction func addNewShop(_ sender: Any) {
/// ask user about shop details and add them here
shopsDataSource.shops.append(Shop())
tableView.reloadData()
}
func showDetailsScreen(shop: Shop) {
/// Go to shop details screen
}
#IBAction func reviewsTapped(_ sender: Any) {
tableView.dataSource = reviewsDataSource
tableView.delegate = reviewsDataSource
tableView.reloadData()
}
#IBAction func addNewReview(_ sender: Any) {
/// ask user about review details and add them here
reviewsDataSource.reviews.append(Review())
tableView.reloadData()
}
func showDetailsScreen(review: Review) {
/// Go to review details screen
}
}

Issues displaying a table view cell from one view controller to another

Right now I am trying to move information from my goal cell into a new table view cell, and am having difficulty getting the cell to display.
Here is the code for my goal cell.
import UIKit
class GoalsViewController: UIViewController {
#IBOutlet weak var tableView: UITableView!
var Goals: [String] = ["goal 1", "goal 2", "goal 3"]
let theEmptyModel: [String] = ["No data in this section."]
var valueToPass = ""
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
func showGoalSelected() {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
let popUp = GoalSelectedPopUp()
self.view.addSubview(popUp)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "GoalConversationsCell_1") {
let viewController = segue.destination as! ActiveGoalsViewController
viewController.Goals.append([valueToPass])
}
}
}
extension GoalsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Goals.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "GoalCell_1", for: indexPath)
cell.textLabel?.text = Goals[indexPath.row]
cell.textLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping
cell.textLabel?.numberOfLines = 3
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
valueToPass = Goals[indexPath.row]
performSegue(withIdentifier: "activeGoalsSegue", sender: self)
Goals.remove(at: indexPath.row)
if Goals.count != 0 {
showGoalSelected()
} else {
Goals.append(contentsOf: theEmptyModel)
}
tableView.reloadData()
}
}
Here is the goal cells storyboard with the push segue connecting it to the other table view.
That other table view is shown below.
Here is the code for this new tableview.
import UIKit
class ActiveGoalsViewController: UIViewController {
#IBOutlet weak var goalTableView: UITableView!
let sections: [String] = ["Mark as Complete:", "History:"]
var goals: [[String]] = [[], []]
let theEmptyModel: [String] = ["No data in this section."]
extension ActiveGoalsViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Goals[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TodayGoalViewCell_1", for: indexPath) as? GoalTableViewCell
cell?.goalLabel.text = Goals[indexPath.section][indexPath.row]
cell?.cellDelegate = self
cell?.index = indexPath
return cell!
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return Goals.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
if Goals[0] != theEmptyModel {
Goals[1].append(Goals[0][indexPath.row])
if Goals[1].first!.contains("No data in this section.") {
Goals[1].removeFirst()
}
Goals[0].remove(at: indexPath.row)
if Goals[0].count == 0 {
Goals[0].append(contentsOf: theEmptyModel)
}
tableView.reloadData()
}
}
}
Once the goal is selected, it sends me to the new storyboard, but this new view does not display the goal that was just added. Can someone help me figure out why this isn't working? Thanks.
I think in the second view controller you need to access the "goals" variable with a lower case g rather then the "Goals" variable with an upper case G.

Getting correct index row from sectioned tableview after JSON download Swift 4

JSON data is already alphabetized before being downloaded. The app correctly divides the data into sections, creates the section title based off of the first letter, and lists all names starting with that letter in the correct section. The problem is each section repeats the same data once it transitions to the detail view controller. Sections B, C, etc. show all of correct names but repeat the "A" names when going to the detail view controller. How can I get the selected cell and the details view controller to match again?
func numberOfSections(in tableView: UITableView) -> Int {
return figuresByLetter.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return figuresByLetter[section].key
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return figuresByLetter[section].value.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "figureCell", for: indexPath)
cell.textLabel?.text = figuresByLetter[indexPath.section].value[indexPath.row].name
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetails", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? FigureViewController {
destination.figure = figures[(tableView.indexPathForSelectedRow?.row)!]
}
}
Let me know if there is any other code needed to answer the question!
struct FigureStats: Decodable {
let name: String
let number: String
let weapon: String?
let desc: String?
let year: String?
}
In the detail view controller:
class FigureViewController: UIViewController {
var figure:FigureStats?
override func viewDidLoad() {
super.viewDidLoad()
nameLabel.text = figure?.name
numberLabel.text = figure?.number
weaponLabel.text = figure?.weapon
descLabel.text = figure?.desc
yearLabel.text = figure?.year
}
}
Try using this property. I hope it helps you.
class YourClass: UIViewController {
var currentFigure: FigureStats!
func numberOfSections(in tableView: UITableView) -> Int {
return figuresByLetter.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return figuresByLetter[section].key
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return figuresByLetter[section].value.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "figureCell", for: indexPath)
cell.textLabel?.text = figuresByLetter[indexPath.section].value[indexPath.row].name
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
currentFigure = figuresByLetter[indexPath.section].value[indexPath.row]
print(currentFigure)
performSegue(withIdentifier: "showDetails", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? FigureViewController {
print(currentFigure)
destination.figure = currentFigure
}
}
class FigureViewController: UIViewController {
var figure:FigureStats?
override func viewDidLoad() {
super.viewDidLoad()
print(figure)
nameLabel.text = figure?.name
numberLabel.text = figure?.number
weaponLabel.text = figure?.weapon
descLabel.text = figure?.desc
yearLabel.text = figure?.year
}
}
I think your problem is that you don't send data to your showDetails (I don't see how you do it) so you see data which did add to storyboard but not data from your model, check it.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetails", sender: indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetails" {
let controller = (segue.destination as! UINavigationController).topViewController as! YourViewController
let row = (sender as! IndexPath).row
controller.figuresByLetter = figuresByLetter[row]
}
}

Restrict table view unless select all cell in swift

i have a table view in which i'm populating data getting from my service. the data is totally dynamic and table view contain sections and cell under it all the things are dynamic. I have a button action outside the table view which is used to add the selected cell data. Now i want to restrict the button that it does not add the data till all the cell under the sections are selected. I want user to first check the cells and than add through add button. My code for the table view is this,
func numberOfSections(in tableView: UITableView) -> Int {
return AddonCategoryModel!.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return AddonCategoryModel![section].name
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 34
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return AddonCategoryModel![section].addonItems.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = addonTableView.dequeueReusableCell(withIdentifier: "addonCell", for: indexPath) as! RestaurantMenuDetailAddonTVC
cell.addonTitleLbl.text = AddonCategoryModel![indexPath.section].addonItems[indexPath.row].name
cell.priceLbl.text = String(AddonCategoryModel![indexPath.section].addonItems[indexPath.row].price)
if selection[indexPath.section].isSelected[indexPath.row] {
cell.radioBtn.setImage(UIImage (named: "radio"), for: UIControlState.normal)
addonItemName = cell.addonTitleLbl.text!
addonItemprice = AddonCategoryModel![indexPath.section].addonItems[indexPath.row].price
addonItemId = AddonCategoryModel![indexPath.section].addonItems[indexPath.row].addonPKcode
addonItemNameArray.append(addonItemName)
addonItemPriceArray.append(addonItemprice)
addonItemIdArray.append(addonItemId)
let defaults = UserDefaults.standard
defaults.set(addonItemName, forKey: "addonItemName")
defaults.set(addonItemprice, forKey: "addonItemPrice")
defaults.set(addonItemId, forKey: "addonItemId")
defaults.synchronize()
}
else {
cell.radioBtn.setImage(UIImage (named: "uncheckRadio"), for: UIControlState.normal)
}
cell.radioBtn.tag = indexPath.row
// cell.radioBtn.addTarget(self, action: #selector(checkBoxSelection(_:)), for: .touchUpInside)
cell.selectionStyle = .none
cell.backgroundColor = UIColor.clear
return cell
}
My screen looks like this,
Basically, you have to set selected true and false based on user have selected the row or deselected the row, then just check in your data set is anything selected if yes then make the button highlighted/enable else disable/unhighlighted
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selection[indexPath.section].isSelected = true
tableView.reloadData()
CheckIfAnyOneIsSelected()
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
selection[indexPath.section].isSelected = false
tableView.reloadData()
CheckIfAnyOneIsSelected()
}
func CheckIfAnyOneIsSelected() {
//loop through your array and check if anyone is selected if yes break the loop and set the button to enable
//else make the button disable
var anyOneSelecte = false
for singleModel in AddonCategoryModel {
for item in addonItems {
if item.isSelected == true
anyOneSelecte = true
break;
}
}
if anyOneSelecte {
//enable your button
} else {
//disable your button
}
}
I have created demo, Let's say you have two Model classes,
class AddOnCategoryModel {
var name: String = ""
var arrValues = [Category]()
init(name: String) {
self.name = name
}
}
class Category {
var name: String = ""
var price : String = ""
var isSelected: Bool = false
}
and following is the mainArray,
for i in 0...2 {
let model = AddOnCategoryModel(name: "Section \(i)")
for j in 0...3 {
let cate = Category()
cate.name = "Category \(j)"
model.arrValues.append(cate)
}
mainArray.append(model)
}
Now considering you have following ListTableCell
There are two IBOutlets
#IBOutlet weak var lblTemp: UILabel!
#IBOutlet weak var btnRadio: UIButton!
FYI. Please set btnRadio default and selected image properly.
Your UITableViewDataSource methods,
func numberOfSections(in tableView: UITableView) -> Int {
return mainArray.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mainArray[section].arrValues.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ListTableCell") as! ListTableCell
let category = mainArray[indexPath.section]
cell.lblTemp.text = category.arrValues[indexPath.row].name
cell.btnRadio.tag = indexPath.row
cell.tag = indexPath.section
cell.btnRadio.addTarget(self, action: #selector(btnRadioTapped), for: .touchUpInside)
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return mainArray[section].name
}
Please find btnRadioTapped method,
#objc func btnRadioTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
let cell = sender.superview?.superview as! ListTableCell
let addOnModel = mainArray[cell.tag]
let category = addOnModel.arrValues[sender.tag]
category.isSelected = sender.isSelected
}
Not let's check all checkbox's are selected or not in button tap event like this,
#IBAction func btnTapped(_ sender: UIButton) {
var isCheckedAll = true
for (_ , item) in mainArray.enumerated() {
let value = item.arrValues.filter({$0.isSelected==false})
if value.count > 0 {
isCheckedAll = false
break;
}
}
print("Done ", isCheckedAll)
}
It will return true if all radioButtons are selected, and return false if any one radioButton is not selected.
Let me know in case of any queries. This is just demo, you have to do minor changes as per your final requirements.
UPDATE
Please find didSelectRowAt indexPath method below,
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let model = mainArray[indexPath.section]
let category = model.arrValues[indexPath.row]
category.isSelected = !category.isSelected
let cell = tableView.cellForRow(at: indexPath) as! ListTableCell
cell.btnRadio.isSelected = category.isSelected
}

Display number of rows on footer

I want to do a simple thing to my app.
Take a look at my main ViewController:
class Page1: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Shared.instance.employees.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell1
cell.nameLabel.text = Shared.instance.employees[indexPath.row].name
cell.positionLabel.text = Shared.instance.employees[indexPath.row].position
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? Page2,
let indexPath = tableView.indexPathForSelectedRow {
destination.newPage = Shared.instance.employees[indexPath.row]
}
}
}
So, what function do I have to add to show the number of rows as I add more and more itens?
Differences between with and without delegates:
Just implement
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "Total \(Shared.instance.employees.count) rows"
}
If you want to customize the title you have to implement tableView:viewForFooterInSection: and return a view for example:
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 30.0))
label.font = UIFont.boldSystemFont(ofSize: 20.0)
label.textAlignment = .center
label.text = "Total \(Shared.instance.employees.count) rows"
return label
}
Side-note: Instead of calling Shared.instance.employees multiple times use a temporary variable:
let employee = Shared.instance.employees[indexPath.row]
cell.nameLabel.text = employee.name
cell.positionLabel.text = employee.position
I solved the stuff doing this -> I inserted a simple label below the Prototype Cell, like this:
Then, I just put this on viewDidLoad:
footerLabel.text = String(Shared.instance.employees.count) + " employees"
By the way, thanks Mr vadian for your help.

Resources