Custom TableView and Header - ios

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
}

Related

UITableViewCell size does not change

I cannot understand why the cells do not resize according to the given .xib file
This is my table controller
import Foundation
import UIKit
class RecipeTableView: UIViewController {
let cellIdentifier = "RecipeTableViewCell"
#IBOutlet weak var recipeTableView: UITableView!
private let localDatabaseManager: LocalDatabaseManager = LocalDatabaseManager.shared
private var recipes = [Recipe]()
override func viewDidLoad() {
super.viewDidLoad()
recipeTableView.dataSource = self
recipeTableView.delegate = self
//recipeTableView.rowHeight = UITableView.automaticDimension
//recipeTableView.estimatedRowHeight = UITableView.automaticDimension
self.recipeTableView.register(UINib(nibName: cellIdentifier, bundle: nil), forCellReuseIdentifier: cellIdentifier)
localDatabaseManager.loadRecipes { [weak self] (recipes) in
guard let recipes = recipes else {
return
}
self?.recipes = recipes
DispatchQueue.main.async {
self?.recipeTableView.reloadData()
}
}
}
// override func viewWillAppear(_ animated: Bool) {
// recipeTableView.estimatedRowHeight = 256
// recipeTableView.rowHeight = UITableView.automaticDimension
// }
}
extension RecipeTableView: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
recipes.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? RecipeTableViewCell else {
return UITableViewCell()
}
let recipe = recipes[indexPath.row]
cell.configure(with: recipe)
//cell.layer.cornerRadius = 32
//cell.layer.masksToBounds = true
return cell
}
}
extension RecipeTableView: UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
}
And my cell swift file
import Foundation
import UIKit
import Kingfisher
import Cosmos
class RecipeTableViewCell: UITableViewCell {
#IBOutlet weak var recipeNameLabel: UILabel!
#IBOutlet weak var recipeDescriptionLabel: UILabel!
#IBOutlet weak var recipeImageView: UIImageView!
#IBOutlet weak var recipeCosmosView: CosmosView!
override func prepareForReuse() {
super.prepareForReuse()
recipeNameLabel.text = nil
recipeDescriptionLabel.text = nil
recipeImageView.image = nil
}
func configure(with recipe: Recipe) {
recipeNameLabel?.text = recipe.name
recipeDescriptionLabel?.text = recipe.description
//let imageBytes = recipe.imageData
//let imageData = NSData(bytes: imageBytes, length: imageBytes.count)
//let image = UIImage(data: imageData as Data)
//recipeImageView?.image = image
let imageUrl = URL(string: recipe.imageData)
recipeImageView?.kf.setImage(with: imageUrl)
recipeCosmosView.settings.fillMode = .precise
recipeCosmosView.rating = recipe.rating
}
}
here is what my custom cell looks like
here is how these cells are shown in the app
I already found similar questions, but everywhere the same answer. Need to add the following lines. So I tried.
override func viewWillAppear(_ animated: Bool) {
recipeTableView.estimatedRowHeight = 256
recipeTableView.rowHeight = UITableView.automaticDimension
}
But it did not work
I think you need to call another tableView method for set the height for each cell according to his content
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// add estimated height here ....
//...
return indexPath.row * 20
}

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.

Firebase import array data to tableview

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
}

Index out of Range Error with Custom TableView

I have two TableViews, both of which are Custom. One of those is a Custom TableView with a Header cell. The second one is a custom TableView without a header cell. What I am trying to do is when someone taps on the first tableView, the tapped item gets added to the second TableView. The problem is when I try to add the second item, the app crashes with an Index Out Of Range Fatal Error. This is in Swift 3.
Here is my Code:
import UIKit
struct TableData {
var section: String = ""
var data = Array<String>()
var dataS = Array<String>()
init(){}
}
var data = Array<TableData>()
var wordData = Array<TableData>()
class MyCustomCell: UITableViewCell {
#IBOutlet var label: UILabel!
#IBOutlet var labelS: UILabel!
}
class MyCustomWordCell: UITableViewCell {
#IBOutlet var wordLabel: UILabel!
#IBOutlet var wordLabelS: UILabel!
}
class MyCustomHeader: UITableViewCell {
#IBOutlet var header: UILabel!
}
class TypeViewController: BaseViewController , UITableViewDelegate, UITableViewDataSource {
#IBOutlet var tableView: UITableView!
#IBOutlet var wordTableView: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return data[section].data.count
}
if tableView == self.wordTableView {
return wordData.count
}
return 0
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "TypeCell", for: indexPath) as! MyCustomCell
cell.label.text = data[indexPath.section].data[indexPath.row]
cell.labelS.text = data[indexPath.section].dataS[indexPath.row]
return cell
}
if tableView == self.wordTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "WordCell", for: indexPath) as! MyCustomWordCell
if wordData.count != 0 {
if wordData.count > indexPath.row {
cell.wordLabel.text = wordData[indexPath.row].data[0]
cell.wordLabelS.text = wordData[indexPath.row].dataS[0]
}
}
return cell
}
return UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
}
func numberOfSections(in tableView: UITableView) -> Int {
if tableView == self.tableView {
return 7
} else {
return 1
}
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if tableView == self.tableView {
let headerCell = tableView.dequeueReusableCell(withIdentifier: "Header") as! MyCustomHeader
headerCell.header.text = data[section].section
return headerCell
}
return UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Header")
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 50.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView == self.tableView {
var element: TableData
element = TableData()
element.data.append(data[indexPath.section].data[indexPath.row]);
element.dataS.append(data[indexPath.section].dataS[indexPath.row]);
wordData.append(element)
wordTableView.reloadData()
if wordData.count == 3 {
performSegue(withIdentifier: "segueFind", sender: self)
}
}
if tableView == self.wordTableView {
wordData.remove(at: indexPath.row)
wordTableView.reloadData()
}
}
override func viewDidLoad() {
super.viewDidLoad()
addSlideMenuButton()
addItems()
}
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 = "Name"
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);
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);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
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);
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);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
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);
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);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
new_elements.data.append(obj31);
new_elements.data.append(obj32);
new_elements.data.append(obj33);
new_elements.data.append(obj34);
new_elements.data.append(obj35);
new_elements.data.append(obj36);
new_elements.data.append(obj37);
new_elements.dataS.append(objS31);
new_elements.dataS.append(objS32);
new_elements.dataS.append(objS33);
new_elements.dataS.append(objS34);
new_elements.dataS.append(objS35);
new_elements.dataS.append(objS36);
new_elements.dataS.append(objS37);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
new_elements.data.append(obj41);
new_elements.data.append(obj42);
new_elements.data.append(obj43);
new_elements.data.append(obj44);
new_elements.data.append(obj45);
new_elements.data.append(obj46);
new_elements.data.append(obj47);
new_elements.dataS.append(objS41);
new_elements.dataS.append(objS42);
new_elements.dataS.append(objS43);
new_elements.dataS.append(objS44);
new_elements.dataS.append(objS45);
new_elements.dataS.append(objS46);
new_elements.dataS.append(objS47);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
new_elements.data.append(obj51);
new_elements.data.append(obj52);
new_elements.data.append(obj53);
new_elements.data.append(obj54);
new_elements.data.append(obj55);
new_elements.data.append(obj56);
new_elements.data.append(obj57);
new_elements.dataS.append(objS51);
new_elements.dataS.append(objS52);
new_elements.dataS.append(objS53);
new_elements.dataS.append(objS54);
new_elements.dataS.append(objS55);
new_elements.dataS.append(objS56);
new_elements.dataS.append(objS57);
data.append(new_elements)
new_elements = TableData()
new_elements.section = "Name"
new_elements.data.append(obj61);
new_elements.data.append(obj62);
new_elements.data.append(obj63);
new_elements.data.append(obj64);
new_elements.data.append(obj65);
new_elements.data.append(obj66);
new_elements.data.append(obj67);
new_elements.dataS.append(objS61);
new_elements.dataS.append(objS62);
new_elements.dataS.append(objS63);
new_elements.dataS.append(objS64);
new_elements.dataS.append(objS65);
new_elements.dataS.append(objS66);
new_elements.dataS.append(objS67);
data.append(new_elements)
}
}
The line where the error is given is the following:
if wordData.count > indexPath.row {
cell.wordLabel.text = wordData[indexPath.section].data[indexPath.row] //This one
cell.wordLabelS.text = wordDataS[indexPath.section].dataS[indexPath.row]
}
Attached are some Photos of the MainStoryboard:
https://www.dropbox.com/sh/s5k50ubas8wewo8/AACTkAsPDtgbOk3EOrb0LeDJa?dl=0
You data structures aren't really helping you here, but your problem is in using indexPath.section in your cellForRow:at: function for the wordTableView.
This function should use wordData[indexPath.row].data[0]:
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "TypeCell", for: indexPath) as! MyCustomCell
cell.label.text = data[indexPath.section].data[indexPath.row]
cell.labelS.text = dataS[indexPath.section].dataS[indexPath.row]
return cell
}
if tableView == self.wordTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "WordCell", for: indexPath) as! MyCustomWordCell
if wordData.count != 0 {
if wordData.count > indexPath.row {
cell.wordLabel.text = wordData[indexPath.row].data[0]
cell.wordLabelS.text = wordDataS[indexPath.row].dataS[0]
}
}
return cell
}
return UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
}
Also, your numberOfRowsInSection is incorrect. It should be:
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return data[section].data.count
}
if tableView == self.wordTableView {
return wordData.count
}
return 0
}

Gets number of rows but doesn't print

I have a program written in Swift 3, that grabs JSON from a REST api and appends it to a table view.
Right now, I'm having troubles with getting it to print in my Tableview, but it does however understand my count function.
So, I guess my data is here, but it just doesn't return them correctly:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, HomeModelProtocal {
#IBOutlet weak var listTableView: UITableView!
func itemsDownloaded(items: NSArray) {
feedItems = items
self.listTableView.reloadData()
}
var feedItems: NSArray = NSArray()
var selectedLocation : Parsexml = Parsexml()
override func viewDidLoad() {
super.viewDidLoad()
self.listTableView.delegate = self
self.listTableView.dataSource = self
let homeModel = HomeModel()
homeModel.delegate = self
homeModel.downloadItems()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier: String = "BasicCell"
let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
let item: Parsexml = feedItems[indexPath.row] as! Parsexml
myCell.textLabel!.text = item.title
return myCell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return feedItems.count
}
override func viewDidAppear(_ animated: Bool) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Are you by any chance able to see the error that I can't see?
Note. I have not added any textlabel to the tablerow, but I guess that there shouldn't be added one, when its custom?
Try this code:
override func viewDidLoad() {
super.viewDidLoad()
print(yourArrayName.count) // in your case it should be like this print(feedItems.count)
}

Resources