我不知道我的tableView: cellForRowAtIndexPath
有什麼問題。它永遠不會因爲某種原因而被召喚。我已經調用了適當的委託和數據源。當我在cellForRowAtIndexPath
函數下添加print("")
行時,它在我模擬應用程序時從不出現。tableview:cellForRowAtIndexPath沒有被調用
謝謝您的高級。
這裏是我的整個頁面代碼:
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.count'在'numberOfRowsInSection'中打印了什麼?另外,如果要在故事板或XIB中添加表格視圖,請嘗試刪除約束並重新添加它們。 – Abhinav
sportCells.count打印0.我認爲它是因爲cellForRowAtIndexPath沒有被調用。我試着刪除約束條件,然後重新添加它們,看看會發生什麼,然後回到你身邊。謝謝 – oatout
'sportCells.count == 0' - >你的問題。 http://stackoverflow.com/questions/33384433/uitableview-does-not-load-data/33384470#33384470 – anhtu