表视图:未调用 cellForRowAtIndexPath

tableview: cellForRowAtIndexPath is not being called

我不知道我的 tableView: cellForRowAtIndexPath 出了什么问题。由于某种原因,它永远不会被调用。我已经调用了正确的委托和数据源。当我在 cellForRowAtIndexPath 函数下添加 print("") 行时,它在我模拟应用程序时从未出现。

在此先感谢您。

这是我对整个页面的代码:

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")
        }


    }



}

从评论中确认,您的问题是模型 sportCells 中的数据填充。

确保正确填充 sportCells,然后调用 self.tableView.reloadData