簡體   English   中英

永遠不會調用cellForRowAtIndexPath

[英]cellForRowAtIndexPath is never called

我有一個故事板,其中包含具有UITableviewUITableViewCell UIViewController ,所有內容均已正確連接,並且已放置UIViewController的所有必需代碼。

當我在模擬器中運行應用程序時,永遠不會調用數據源功能cellForRowAtIndexPath之一,但會調用numberOfRowsInSection

  • 調用“ func tableView(tableView:UITableView,numberOfRowsInSection部分:Int)-> Int”
  • 但是從來沒有調用過“ func tableView(tableView:UITableView,cellForRowAtIndexPath indexPath:NSIndexPath)-> UITableViewCell”

下面是我的視圖控制器代碼:

import UIKit

class DVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{

    @IBOutlet var tableView : UITableView?
    var tableData = ["Row 1", "Row 2", "Row 3"]
    let kCellID = "cell"

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.tableView?.delegate = self;
        self.tableView?.dataSource = self;

        //load cell
        self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: kCellID);
        self.tableView?.reloadData();
    }

    //MARK: Tableview delegates
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return self.tableData.count;
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
       //var cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: kCellID)
        let cell : UITableViewCell = UITableViewCell (style: UITableViewCellStyle.Default, reuseIdentifier: kCellID);
        return cell;
    }
}

有人可以建議為什么從未調用cellForRowAtIndexPath嗎?

這就是我所做的,僅卸載了Xcode 5和6,僅重新安裝了Xcode 6,運行了該項目,然后進行了工作。 經過2天的調試,重新安裝成功了。

我剛剛檢查了您的代碼,它可以正常工作。
檢查是否調用了numberOfRowsInSection 如果沒有,請檢查情節提要中的連接。

嘗試這個:

MainViewController類:UIViewController,UITableViewDataSource,UITableViewDelegate {

func viewDidLoad(){

super.viewDidLoad()

tableView.dataSource =自我

tableView.delegate =自我

}

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM