Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios tableview:未调用cellForRowAtIndexPath_Ios_Tableview_Swift2_Ios9_Xcode7 - Fatal编程技术网

Ios tableview:未调用cellForRowAtIndexPath

Ios tableview:未调用cellForRowAtIndexPath,ios,tableview,swift2,ios9,xcode7,Ios,Tableview,Swift2,Ios9,Xcode7,我无法找出我的表格视图:cellforrowatinexpath有什么问题。它永远不会因为某种原因被呼叫。我已经调用了适当的委托和数据源。当我在cellforrowatinexpath函数下添加print(“”)行时,它在模拟应用程序时从未出现过 提前谢谢你 以下是我的整个页面代码: class MainPageViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var sportCell

我无法找出我的
表格视图:cellforrowatinexpath
有什么问题。它永远不会因为某种原因被呼叫。我已经调用了适当的委托和数据源。当我在
cellforrowatinexpath
函数下添加
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

从评论中确认,问题在于型号
sportCells
中的数据填充


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

numberOfRowsInSection
中打印的
sportCells.count
是什么?此外,如果要在序列图像板或XIB中添加表视图,请尝试删除约束并重新添加。sportCells.count打印0。我想这是因为没有调用CellForRowatineXpath。我会尝试删除这些约束,然后重新添加它们,看看会发生什么,然后再回复您。谢谢
sportCells.count==0
->您的问题。问题在于方法updateSportsTable()。由于您没有将数据保存在名为“sportCells”的数组中,所以您可以开始了
sportCells.count
必须为您的
cellforrowatinexpath
返回正值才能被调用。确保正确填充
sportCells
,并调用
self.tableView.reloadData
发布。在
numberOfRowsInSection
中打印的
sportCells.count
是什么?此外,如果要在序列图像板或XIB中添加表视图,请尝试删除约束并重新添加。sportCells.count打印0。我想这是因为没有调用CellForRowatineXpath。我会尝试删除这些约束,然后重新添加它们,看看会发生什么,然后再回复您。谢谢
sportCells.count==0
->您的问题。问题在于方法updateSportsTable()。由于您没有将数据保存在名为“sportCells”的数组中,所以您可以开始了
sportCells.count
必须为您的
cellforrowatinexpath
返回正值才能被调用。确保正确填充了
sportCells
,并且调用了
self.tableView.reloadData
post。如果sportCells在cellForRowAtIndexPath下填充,该如何填充?我是否遗漏了一个简单的想法…我想我的问题是这行代码:query.findobjectsinbackgroundithblock{(sportCells:[PFObject]?,错误:NSError?->Void in…..如果我尝试使用[AnyObject]代替PFObject,Xcode崩溃,所有代码文本变为黑色…您从未在
CellForRowatineXpath
中加载模型。在
viewDidLoad
中加载数据,然后调用
self.tableView.reloadData
。如果在CellForRowatineXpath下填充sportCells,该如何填充它?我是否缺少一个简单的示例这里的想法…我想我的问题是这行代码:query.findobjectsinbackgroundithblock{(sportCells:[PFObject]?,error:NSError?->Void in.…如果我尝试使用[AnyObject]代替PFObject,Xcode崩溃,所有代码文本变为黑色…您永远不会在
cellforrowatinexpath
中加载模型。在
viewDidLoad
中加载数据,然后调用
self.tableView.reloadData