简体   繁体   English

tableview:cellForRowAtIndexPath没有被调用

[英]tableview: cellForRowAtIndexPath is not being called

I can't figure out what is wrong with my tableView: cellForRowAtIndexPath . 我无法弄清楚tableView: cellForRowAtIndexPath有什么问题。 its never getting called for some reason. 它永远不会因为某种原因被召唤。 i have called the proper delegate and datasource. 我已经调用了适当的委托和数据源。 When I add a print("") line under the cellForRowAtIndexPath function, it never appears when i simulate the app. 当我在cellForRowAtIndexPath函数下添加print("")行时,当我模拟该应用程序时它永远不会出现。

Thank you in advanced. 在此先感谢您。

here is my code for the whole page: 这是我整个页面的代码:

class MainPageViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var sportCells = [PFObject]()


@IBOutlet weak var tableView: UITableView!

@IBOutlet weak var profilePictureImageView: UIImageView!
@IBOutlet weak var fullNameLabel: UILabel!





override func viewDidLoad() {
    super.viewDidLoad()

    self.tableView.dataSource = self
    self.tableView.delegate = self

    //Do any additional setup after loading the view.
}
override func viewDidAppear(animated: Bool) {
    updateSportsTable()
    print("its happening")
    let lastName = PFUser.currentUser()! ["last_name"]
    if let firstName = PFUser.currentUser()?["first_name"] as? String {
        self.fullNameLabel.text = "\(firstName) \(lastName)"


    }

    if let userPicture = PFUser.currentUser()?["profile_picture"] as? PFFile {
        userPicture.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
            if (error == nil) {
                self.profilePictureImageView.image = UIImage(data:imageData!)


            }
        }
    }
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print("sportCells count is \(sportCells.count)")
    return sportCells.count

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    print("data extracted1")
    let cell = tableView.dequeueReusableCellWithIdentifier("sportCell") as! SportTableViewCell
   print("data extracted")
    let sportPost = self.sportCells[indexPath.row]
    let user = sportPost["user"] as! PFUser
    print("data extracted")
    do {
        try user.fetchIfNeeded()
        print("its happening 3rd time")
    } catch _ {
        print("There was an error")
    }

    cell.sportTitle.text = sportPost["basketballTitle"] as? String
    cell.sportLogo.text = sportPost["basketballLogo"] as? String
    cell.numberOfPOTM.text = "5"
    return cell
}



func updateSportsTable() {
    let query = PFQuery(className: "Sports")
    query.findObjectsInBackgroundWithBlock { (sportCells:[PFObject]?, error:NSError?) -> Void in
        if error == nil {
            self.tableView.reloadData()
            print("its happening again")
        }


    }



}

As confirmed from the comments, you problem is data population in model sportCells . 如评论所确认,您的问题是模型sportCells数据填充。

Ensure that sportCells is populated properly and that you call self.tableView.reloadData after that. 确保正确填充sportCells ,然后再调用self.tableView.reloadData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM