Firebase import array data to tableview - ios

I have tableview in VC and I would like to import "Detail" item form current recipe:
Firebase entries
to tableView - each to a separate cell.
My Code in RecipiesModel:
class RecipiesModel {
var title: String?
var desc: String?
var detail: Array<Any>?
init(title: String?, desc: String?, detail: Array<Any>?){
self.title = title
self.desc = desc
self.detail = detail
}
}
My Code in VC:
import UIKit
import FirebaseDatabase
class DescriptionViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var textInput: String = ""
var descInput: String = ""
var ref:DatabaseReference!
var recipiesList = [RecipiesModel]()
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var titleLabelDesc: UILabel!
#IBOutlet weak var descriptionLabelDesc: UILabel!
#IBOutlet weak var imageView: UIImageView!
#IBOutlet weak var tabBarView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarStyle = .lightContent
tableView.delegate = self
tableView.dataSource = self
customUIView()
titleLabelDesc.text = textInput
descriptionLabelDesc.text = descInput
loadList()
}
//Database
func loadList() {
ref = Database.database().reference()
ref.child("Recipies").observe(.childAdded, with: { (snapshot) in
let results = snapshot.value as? [String : AnyObject]
let title = results?["Recipies title"]
let desc = results?["Recipies description"]
let detail = results?["Detail"]
let myRecipies = RecipiesModel(title: title as! String?, desc: desc as! String?, detail: detail as! Array<Any>?)
self.recipiesList.append(myRecipies)
DispatchQueue.main.async {
self.tableView.reloadData()
}
})
}
func customUIView() {
tabBarView.layer.shadowColor = UIColor.lightGray.cgColor
tabBarView.layer.shadowOpacity = 1
tabBarView.layer.shadowOffset = CGSize.zero
tabBarView.layer.shadowRadius = 3
}
#IBAction func dismissButton(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
//TableView
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recipiesList.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellDescription") as! TableViewCellDescription
let recipies = recipiesList[indexPath.row]
cell.recipiesModuleLabel.text = recipies.detail?.description
return cell
}
}
At this moment the result is:
Table View Entries
Any ideas?

In your case you want to show details items in different row whereas you have array of RecipiesModel.
var recipiesList = [RecipiesModel]()
In case you can represent each modal object of array as a section and details object as their rows. You can do that as:
// TableView datasource and delegate methods
func numberOfSections(in tableView: UITableView) -> Int {
return recipiesList.count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let modal = recipiesList[section]
return "\(modal.title ?? ""): \(modal.desc ?? "")"
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recipiesList[section].detail?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellDescription") as! TableViewCellDescription
if let detailName = recipiesList[indexPath.section].detail?[indexPath.row] as? String {
cell.recipiesModuleLabel.text = detailName
} else {
cell.recipiesModuleLabel.text = ""
}
return cell
}

Related

Swift TableView segue to new ViewController with wrong index path (penultimate selection)

I have a weird problem.
I have two TableViews one for showing Projects and one for showing all Team Members. With both TableViews I have the same bug.
When a user clicks on a Project/ Team Member I want to show the Details for it.
The weird thing is, when running the app and I select a Project/ Team Member for the first time, nothing is happening. When I then select another one, it shows me the details of the previous selected one.
I hope someone can help me with that.
Also a weird thing is, the entry "Sarra Fezzani" was deleted from the Firebase Database and the app was clean build, but it still shows it several times...
Since both codes are pretty similiar I will only post the Code for the ProjetTableViewController without the other files.
//
// TeamViewController.swift
// ProLabArtv2
//
import UIKit
class TeamViewController: UIViewController {
// MARK: - Properties
#IBOutlet weak var memberTableView: UITableView!
#IBOutlet weak var addTeamMember: UIButton!
var members = [TeamMember]()
var textToBeSent: String = ""
override func viewDidLoad() {
super.viewDidLoad()
setUpElements()
UserService.members(for: User.current) { (members) in
self.members = members
self.memberTableView.reloadData()
}
}
// MARK: - Element Style
func setUpElements() {
// Mark: Style the elements
Utilities.addShadowtoButton(addTeamMember)
}
func configureTableView() {
// remove separators for empty cells
memberTableView.tableFooterView = UIView()
// remove separators from cells
memberTableView.separatorStyle = .none
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toMemberDetails" {
let destVC = segue.destination as! TeamMemberDetailsViewController
destVC.member = sender as? TeamMember
}
}
}
// MARK: - UITableViewDataSource
extension TeamViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let member = members[indexPath.row]
let cell = memberTableView.cellForRow(at: indexPath)
print(members)
performSegue(withIdentifier: "toMemberDetails", sender: member)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return members.count
}
// func numberOfSections(in tableView: UITableView) -> Int {
// return members.count
// }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let member = members[indexPath.row]
let cell = memberTableView.dequeueReusableCell(withIdentifier: "TeamMemberCell") as! TeamMemberCell
cell.jobLabel.text = members[indexPath.row].memberJob
cell.nameLabel.text = members[indexPath.row].memberName
return cell
}
}
// MARK: - UITableViewDelegate
extension TeamViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
}
import UIKit
class TeamMemberCell: UITableViewCell {
// MARK: - Properties
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var jobLabel: UILabel!
static let height: CGFloat = 78
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
import Foundation
import UIKit
import FirebaseDatabase.FIRDataSnapshot
class TeamMember {
// Next let's add properties to store all the additional information we need. Add the following to your post class.
var key: String?
let memberName: String
let memberJob: String
let memberLanguage: String
let memberPrice: String
let memberSpecification: String
// You'll get some compiler errors for not having any initializers or default values for certain properties. Let's go ahead and fix that:
init(memberName: String, memberJob: String, memberLanguage: String, memberPrice: String, memberSpecification: String) {
self.memberName = memberName
self.memberJob = memberJob
self.memberLanguage = memberLanguage
self.memberPrice = memberPrice
self.memberSpecification = memberSpecification
}
var dictValue: [String : Any] {
return ["memberName" : memberName,
"memberJob" : memberJob,
"memberLanguage" : memberLanguage,
"memberPrice" : memberPrice,
"memberSpecification" : memberSpecification]
}
init?(snapshot: DataSnapshot) {
guard let dict = snapshot.value as? [String : Any],
let memberName = dict["memberName"] as? String,
let memberJob = dict["memberJob"] as? String,
let memberLanguage = dict["memberLanguage"] as? String,
let memberPrice = dict["memberPrice"] as? String,
let memberSpecification = dict["memberSpecification"] as? String
else { return nil }
self.key = snapshot.key
self.memberName = memberName
self.memberJob = memberJob
self.memberLanguage = memberLanguage
self.memberPrice = memberPrice
self.memberSpecification = memberSpecification
}
}
import Foundation
import FirebaseAuth.FIRUser
import FirebaseDatabase
import FirebaseUI
import FirebaseAuth
struct UserService {
static func members(for user: User, completion: #escaping ([TeamMember]) -> Void) {
let ref = Database.database().reference().child("team").child(user.uid)
ref.observeSingleEvent(of: .value, with: { (snapshot) in
guard let snapshot = snapshot.children.allObjects as? [DataSnapshot] else {
return completion([])
}
let members = snapshot.reversed().compactMap(TeamMember.init)
completion(members)
})
}
}
//
// TeamMemberDetailsViewController.swift
// ProLabArtv2
//
// Created by Manu on 09.06.20.
// Copyright © 2020 Manuel Knott. All rights reserved.
//
import UIKit
import FirebaseDatabase
import FirebaseAuth
import FirebaseStorage
class TeamMemberDetailsViewController: UIViewController {
// MARK: - Properties
#IBOutlet weak var nameLabel: UILabel!
#IBOutlet weak var jobLabel: UILabel!
#IBOutlet weak var specificationLabel: UILabel!
#IBOutlet weak var languageLabel: UILabel!
#IBOutlet weak var priceLabel: UILabel!
#IBOutlet weak var scoreLabel: UILabel!
#IBOutlet weak var newScoreButton: UIButton!
#IBOutlet weak var projectsPartButton: UIButton!
var member: TeamMember?
override func viewDidLoad() {
super.viewDidLoad()
setUI()
}
func setUI() {
nameLabel.text = member?.memberName
jobLabel.text = member?.memberJob
specificationLabel.text = member?.memberSpecification
languageLabel.text = member?.memberLanguage
priceLabel.text = member?.memberPrice
// scoreLabel.text = member?.
}
}
And that's the one for the ProjectViewController, where I am using a switch statement...
// HomeViewController.swift
// ProLabArtv2
//
//
import UIKit
import Kingfisher
import Foundation
import FirebaseStorage
import FirebaseDatabase
class HomeViewController: UIViewController {
// MARK: - Properties
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var addProject: UIButton!
var posts = [Post]()
var textToBeSent: String = ""
override func viewDidLoad() {
super.viewDidLoad()
UserService.posts(for: User.current) { (posts) in
self.posts = posts
self.tableView.reloadData()
}
Utilities.addShadowtoButton(addProject)
}
func configureTableView() {
// remove separators for empty cells
tableView.tableFooterView = UIView()
// remove separators from cells
tableView.separatorStyle = .none
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "toDetails" {
let destVC = segue.destination as! ShowProjectDetailsViewController
destVC.post = sender as? Post
}
}
}
// MARK: - UITableViewDataSource
extension HomeViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let post = posts[indexPath.row]
performSegue(withIdentifier: "toDetails", sender: post)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func numberOfSections(in tableView: UITableView) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let post = posts[indexPath.section]
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "PostImageCell") as! PostImageCell
let imageURL = URL(string: post.imageURL)
cell.postImageView.kf.setImage(with: imageURL)
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "PostSubCell") as! PostSubCell
cell.projectName.text = post.projectTitle
return cell
default:
fatalError("Error: unexpected indexPath.")
}
}
}
// MARK: - UITableViewDelegate
extension HomeViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.row {
case 0:
let post = posts[indexPath.section]
return post.imageHeight
case 1:
return PostSubCell.height
default:
fatalError()
}
}
}
Hopefully someone can help me :)
This is one of those errors we've all made at some point, usually by not reading the autocomplete carefully.
Your code is
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
You've used the didDeselectRowAt rathert than didSelectRowAt method. Which means that it runs it when that row loses focus (which will be when you click on another row).
You need
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
...
You are using the wrong delegate method. Perform the segue on selecting rather than deselecting a cell
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let post = posts[indexPath.row]
performSegue(withIdentifier: "toDetails", sender: post)
}

How to pass data with delegate from footer cell to view controller?

Ive been stuck trying to pass data from the FoodEatenController(FEC) Footer to the TotalCaloriesController. The code that I have now it shows NOTHING in the calorieLbl of the TotalCalorieController(TCC).
The delegate that ive been using to pass the data from the FEC to the TCC does not pass the text/string data that is in the FoodFooter calorieTotallbl to the TEC calorieLbl
the data that populates the cells of the FEC is retrieved from Cloud Firestore and passed in from anotherView Controller (FoodPickerController)
import UIKit
class FoodEatenController: UIViewController{
var selectedFood: FoodList! // allows data to be passed into the VC
// allows data to be sepearted into sections
var foodItems: [FoodItem] = []
var groupedFoodItems: [String: [FoodItem]] = [:]
var dateSectionTitle: [String] = []
#IBOutlet weak var tableView: UITableView!
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? TotalCalorieController {
}
}
}
extension FoodEatenController: UITableViewDelegate, UITableViewDataSource{
func numberOfSections(in tableView: UITableView) -> Int {
return dateSectionTitle.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let date = dateSectionTitle[section]
return groupedFoodItems[date]!.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let foodCell = tableView.dequeueReusableCell(withIdentifier: "FoodCell") as! FoodCell
let date = dateSectionTitle[indexPath.section]
let foodItemsToDisplay = groupedFoodItems[date]![indexPath.row]
foodCell.configure(withCartItems: fooditemsToDisplay.foodList)
return foodCell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let foodHeader = tableView.dequeueReusableCell(withIdentifier: "FoodHeader") as! FoodHeader
let headerTitle = dateSectionTitle[section]
foodHeader.dateLbl.text = "Date: \(headerTitle)"
return foodHeader
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let foodFooter = tableView.dequeueReusableCell(withIdentifier: "FoodFooter") as! FoodFooter
let date = dateSectionTitle[section]
let arrAllItems = groupedFoodItems[date]!
var total: Float = 0
for item in arrAllItems {
let eaten = item.productList
let selectedMeal = item.foodList.selectedOption
if selectedMeal == 1 {
total = total + (Float(eaten!.calorie))
}
}
foodFooter.calorieTotal.text = String(subtotal!)
foodFooter.delegate = self
return foodFooter
}
}
extension FoodEatenController: EatenFoodDelegate {
func onTouchCaloireInfo(info: String) {
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "AdditionalCostsVC") as! TotalCalorieController
popUp.calorieLbl.text = info
}
}
import UIKit
protocol EatenFoodDelegate: class {
func onTouchCaloireInfo(info: String)
}
class FoodFooter: UITableViewCell {
weak var delegate: EatenFoodDelegate? = nil
#IBOutlet weak var calorieTotal: UILabel!
#IBOutlet weak var totalInfoBtn: UIButton!
#IBAction func totalOnClicked(_ sender: AnyObject) {
self.delegate?. onTouchCaloireInfo(info: calorieTotal.text!)
}
}
class TotalCalorieController: UIViewController, EatenFoodDelegate {
func onTouchCaloireInfo(info: String) {
calorieLbl.text = info
}
#IBOutlet weak var calorieLbl: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func returnButton(_ sender: Any) {
dismiss(animated: true, completion: nil)
print("Close Taxes and Fees")
}
}
Add the following line at the end of the func onTouchCaloireInfo(info:)
self.present(popUp, animated: true, completion: nil)
If you would like to be sure that the function onTouchCaloireInfo(info:) gets called, just add the following line:
debugPrint("onTouchCaloireInfo")
And check, if it prints the given string in the console of the Xcode
extension FoodEatenController: EatenFoodDelegate {
func onTouchCaloireInfo(info: String) {
debugPrint("onTouchCaloireInfo")
let popUp = self.storyboard?.instantiateViewController(withIdentifier: "AdditionalCostsVC") as! TotalCalorieController
self.present(popUp, animated: true) {
popUp.calorieLbl.text = info
}
}
}

DidSelectRowAt won't return desired item

I have dynamic table which displays a number of MKMapItems - these items are being displayed by cellForRowAt. But somehow if I click on the cell didSelectRow won't return the map item if I want to print it:
class SearchResultTableViewController: UIViewController {
#IBOutlet weak var searchBar: UISearchBar!
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var visualEffectView: UIVisualEffectView!
private enum SegueID: String {
case showDetail
case showAll
}
private enum CellReuseID: String {
case resultCell
}
private var places: [MKMapItem]? {
didSet {
tableView.reloadData()
}
}
private var suggestionController: SuggestionsTableTableViewController!
var searchController: UISearchController!
private var localSearch: MKLocalSearch? {
willSet {
places = nil
localSearch?.cancel()
}
}
private var boundingRegion: MKCoordinateRegion?
override func awakeFromNib() {
super.awakeFromNib()
...
}
override func viewDidLoad() {
super.viewDidLoad()
...
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if #available(iOS 10, *) {
visualEffectView.layer.cornerRadius = 9.0
visualEffectView.clipsToBounds = true
}
}
...
}
extension SearchResultTableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return places?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: CellReuseID.resultCell.rawValue, for: indexPath)
if let mapItem = places?[indexPath.row] {
cell.textLabel?.text = mapItem.name
cell.detailTextLabel?.text = mapItem.placemark.formattedAddress
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
print(indexPath)
...
guard let mapItem = places?[indexPath.row] else { return }
print(mapItem.name)
...
if tableView == suggestionController.tableView, let suggestion = suggestionController.completerResults?[indexPath.row] {
searchController.isActive = false
searchController.searchBar.text = suggestion.title
search(for: suggestion)
}
}
}
guard let mapItem = places?[indexPath.row] else { return }
- are you sure this guard statement isn't returning?
also, I'm not seeing where you're setting the VC as the tableView delegate/datasource.

How to reload TableVIew Using Model NSObject Class with MVVM

I want to reload TableView without tableview.reloadData() method for that i have used MVVM structure so i have attach model class to storyboard and the issue is that my tableview is reload first and then i get all data how should i solved this issue please help me if any one have a solution !!
This is storyboard model attach
Model Code :-
class MovieModel: Decodable{
var artistName: String = ""
var trackName: String = ""
init(artistName: String, trackName: String){
self.artistName = artistName
self.trackName = trackName
}
}
class ResultModel: Decodable{
var results = [MovieModel]()
init(results: [MovieModel]) {
self.results = results
}
}
My ViewModel File code :-
class MovieViewModel: NSObject {
var artistName: String = ""
var trackName: String = ""
var movieModel: MovieModel?
var movieData = [MovieViewModel]()
override init() {
}
init(movie: MovieModel) {
self.artistName = movie.artistName
self.trackName = movie.trackName
}
func getData(){
Service.shareInstance.getAllMovieData { (movie, error) in
if error == nil{
self.movieData = movie?.map({return MovieViewModel(movie: $0)}) ?? []
print(self.movieData)
}else{
print("\(String(describing: error))")
}
}
}
func numberOfRow(section:Int) -> Int{
return movieData.count
}
func cellForRow(indexPath: IndexPath) -> MovieViewModel{
return self.movieData[indexPath.row]
}
}
My ViewController Code :-
class ViewController: UIViewController {
#IBOutlet var movieVM: MovieViewModel?
#IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.movieVM?.getData()
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return movieVM?.numberOfRow(section: section) ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
let movie = movieVM?.cellForRow(indexPath: indexPath)
cell?.textLabel?.text = movie?.artistName
cell?.detailTextLabel?.text = movie?.trackName
return cell!
}
}
In my case i am not reload tableview all this is done using ModelClass ! Thank You !!

Custom TableView and Header

I have a single Custom TableView with a Header cell. The problem is that I am only able to display one set of data and the TableView will not currently scroll (Maybe because of only one set of data being displayed.) This is in Swift 3.
Here is my Code:
ViewController:
struct TableData {
var section: String = ""
var data = Array<String>()
var dataS = Array<String>()
init(){}
}
var data = Array<TableData>()
var dataS = Array<TableData>()
class MyCustomCell: UITableViewCell {
#IBOutlet var label: UILabel!
#IBOutlet var labelS: UILabel!
}
class MyCustomHeader: UITableViewCell {
#IBOutlet var header: UILabel!
}
class TypeViewController: BaseViewController , UITableViewDelegate, UITableViewDataSource {
#IBOutlet var tableView: UITableView!
#IBOutlet var scrollView: UIScrollView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data[section].data.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! MyCustomCell
cell.label.text = data[indexPath.section].data[indexPath.row]
cell.labelS.text = dataS[indexPath.section].data[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCell(withIdentifier: "Header") as! MyCustomHeader
headerCell.header.text = data[section].section
return headerCell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
var element: TableData
element = TableData()
element.data.append(data[indexPath.section].data[indexPath.row]);
wordData.append(element)
element = TableData()
element.data.append(dataS[indexPath.section].dataS[indexPath.row]);
wordDataS.append(element)
if wordData[indexPath.section].data.count == 3 {
performSegue(withIdentifier: "segueFind", sender: self)
}
}
override func viewDidLoad() {
super.viewDidLoad()
addSlideMenuButton()
addItems()
print(data)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func addItems() {
var new_elements:TableData
new_elements = TableData()
new_elements.section = "Gevurah - Judgement"
new_elements.data.append(obj1);
new_elements.data.append(obj2);
new_elements.data.append(obj3);
new_elements.data.append(obj4);
new_elements.data.append(obj5);
new_elements.data.append(obj6);
new_elements.data.append(obj7);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Hod - Reverberation"
new_elements.data.append(obj11);
new_elements.data.append(obj12);
new_elements.data.append(obj13);
new_elements.data.append(obj14);
new_elements.data.append(obj15);
new_elements.data.append(obj16);
new_elements.data.append(obj17);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Tiferet - Beauty"
new_elements.data.append(obj21);
new_elements.data.append(obj22);
new_elements.data.append(obj23);
new_elements.data.append(obj24);
new_elements.data.append(obj25);
new_elements.data.append(obj26);
new_elements.data.append(obj27);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Gevurah - Judgement"
new_elements.dataS.append(objS1);
new_elements.dataS.append(objS2);
new_elements.dataS.append(objS3);
new_elements.dataS.append(objS4);
new_elements.dataS.append(objS5);
new_elements.dataS.append(objS6);
new_elements.dataS.append(objS7);
dataS.append(new_elements)
new_elements = TableData()
new_elements.section = "Hod - Reverberation"
new_elements.dataS.append(objS11);
new_elements.dataS.append(objS12);
new_elements.dataS.append(objS13);
new_elements.dataS.append(objS14);
new_elements.dataS.append(objS15);
new_elements.dataS.append(objS16);
new_elements.dataS.append(objS17);
dataS.append(new_elements)
new_elements = TableData()
new_elements.section = "Tiferet - Beauty"
new_elements.dataS.append(objS21);
new_elements.dataS.append(objS22);
new_elements.dataS.append(objS23);
new_elements.dataS.append(objS24);
new_elements.dataS.append(objS25);
new_elements.dataS.append(objS26);
new_elements.dataS.append(objS27);
dataS.append(new_elements)
}
Also, I am getting an index out of range error on this line:
element.data.append(dataS[indexPath.section].dataS[indexPath.row]);
Attached are some Photos of the MainStoryboard:
https://i.stack.imgur.com/Yvw7I.png
i.stack.imgur.com/nLWZJ.png
https://i.stack.imgur.com/ralOb.png
Put some code for number of section in your class it will definitely work.
public func numberOfSections(in tableView: UITableView) -> Int
{
return dummyArray.count
}

Resources