Reputation: 1302
I have my table view class and Cell class. I fetch the data from an API that I know returns data(I can even see it in the debugger) but somehow the cells never load any data. Whats even more strange is that if I set a breakpoint inside of the table view datasource extension functions it will never trigger. I'm not sure what I'm missing.
Here is what I've done so far:
Table view controller
import Foundation
import UIKit
class MainComment: UIViewController{
@IBOutlet weak var commentTable: UITableView!
var arrayComments = [CommentBE]()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.getPostComments();
}
func getPostComments() {
CommentWS.getCommentsByPost(g_activePostId, success: {
arrayComments in
self.arrayComments = arrayComments
self.commentTable.reloadData()
}, error: {
(errorMessage) in
print(errorMessage)
})
}
@IBOutlet weak var ViewContent: UIView!
}
extension MainComment: UITableViewDataSource { //number, number, cellfor
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.arrayComments.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentidier = "commentCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentidier, for: indexPath) as! MainCelda
//cell.delegate = self
cell.objComment = self.arrayComments[indexPath.row]
return cell
}
}
Cell:
import Foundation
import UIKit
class MainCelda : UITableViewCell{
@IBOutlet weak var commentDate: UILabel!
@IBOutlet weak var personProfilePic: UIImageView!
@IBOutlet weak var personName: UIButton!
@IBOutlet weak var commentText: UILabel!
var poster: PersonBE!
var objComment: CommentBE! {
didSet {
self.updateData()
}
}
private func updateData() {
self.getPoster(personId: objComment.personId)
self.commentText.text = self.objComment.commentText
/*
self.imgPost.downloadImageInUrlString(Constants.image_fs + self.objPost.pictureUrl) { (image, urlString) in
self.imgPost.image = image
}*/
self.personName.setTitle(self.poster.displayName, for: .normal)
}
func getPoster(personId: String) {
PersonWS.getPersonByPersonId(personId, success: {(person) in
self.poster = person
}, error: {(errorMessage) in
print(errorMessage)
})
}
}
Thanks!
Upvotes: 1
Views: 34
Reputation: 534950
if I set a breakpoint inside of the table view datasource extension functions it will never trigger
Maybe because you’re not the datasource? Let’s be certain. In viewDidLoad
, say
self.commentTable.dataSource = self
Upvotes: 2